sys_sparc32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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;
  189. error = vfs_fstatat(dfd, filename, &stat, flag);
  190. if (error)
  191. return error;
  192. return cp_compat_stat64(&stat, statbuf);
  193. }
  194. asmlinkage long compat_sys_sysfs(int option, u32 arg1, u32 arg2)
  195. {
  196. return sys_sysfs(option, arg1, arg2);
  197. }
  198. asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid, struct compat_timespec __user *interval)
  199. {
  200. struct timespec t;
  201. int ret;
  202. mm_segment_t old_fs = get_fs ();
  203. set_fs (KERNEL_DS);
  204. ret = sys_sched_rr_get_interval(pid, (struct timespec __user *) &t);
  205. set_fs (old_fs);
  206. if (put_compat_timespec(&t, interval))
  207. return -EFAULT;
  208. return ret;
  209. }
  210. asmlinkage long compat_sys_rt_sigprocmask(int how,
  211. compat_sigset_t __user *set,
  212. compat_sigset_t __user *oset,
  213. compat_size_t sigsetsize)
  214. {
  215. sigset_t s;
  216. compat_sigset_t s32;
  217. int ret;
  218. mm_segment_t old_fs = get_fs();
  219. if (set) {
  220. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  221. return -EFAULT;
  222. switch (_NSIG_WORDS) {
  223. case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  224. case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  225. case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  226. case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  227. }
  228. }
  229. set_fs (KERNEL_DS);
  230. ret = sys_rt_sigprocmask(how,
  231. set ? (sigset_t __user *) &s : NULL,
  232. oset ? (sigset_t __user *) &s : NULL,
  233. sigsetsize);
  234. set_fs (old_fs);
  235. if (ret) return ret;
  236. if (oset) {
  237. switch (_NSIG_WORDS) {
  238. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  239. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  240. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  241. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  242. }
  243. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  244. return -EFAULT;
  245. }
  246. return 0;
  247. }
  248. asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
  249. compat_size_t sigsetsize)
  250. {
  251. sigset_t s;
  252. compat_sigset_t s32;
  253. int ret;
  254. mm_segment_t old_fs = get_fs();
  255. set_fs (KERNEL_DS);
  256. ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
  257. set_fs (old_fs);
  258. if (!ret) {
  259. switch (_NSIG_WORDS) {
  260. case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
  261. case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
  262. case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
  263. case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
  264. }
  265. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  266. return -EFAULT;
  267. }
  268. return ret;
  269. }
  270. asmlinkage long compat_sys_rt_sigqueueinfo(int pid, int sig,
  271. struct compat_siginfo __user *uinfo)
  272. {
  273. siginfo_t info;
  274. int ret;
  275. mm_segment_t old_fs = get_fs();
  276. if (copy_siginfo_from_user32(&info, uinfo))
  277. return -EFAULT;
  278. set_fs (KERNEL_DS);
  279. ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *) &info);
  280. set_fs (old_fs);
  281. return ret;
  282. }
  283. asmlinkage long compat_sys_sigaction(int sig, struct old_sigaction32 __user *act,
  284. struct old_sigaction32 __user *oact)
  285. {
  286. struct k_sigaction new_ka, old_ka;
  287. int ret;
  288. WARN_ON_ONCE(sig >= 0);
  289. sig = -sig;
  290. if (act) {
  291. compat_old_sigset_t mask;
  292. u32 u_handler, u_restorer;
  293. ret = get_user(u_handler, &act->sa_handler);
  294. new_ka.sa.sa_handler = compat_ptr(u_handler);
  295. ret |= __get_user(u_restorer, &act->sa_restorer);
  296. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  297. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  298. ret |= __get_user(mask, &act->sa_mask);
  299. if (ret)
  300. return ret;
  301. new_ka.ka_restorer = NULL;
  302. siginitset(&new_ka.sa.sa_mask, mask);
  303. }
  304. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  305. if (!ret && oact) {
  306. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  307. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  308. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  309. ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  310. }
  311. return ret;
  312. }
  313. asmlinkage long compat_sys_rt_sigaction(int sig,
  314. struct sigaction32 __user *act,
  315. struct sigaction32 __user *oact,
  316. void __user *restorer,
  317. compat_size_t sigsetsize)
  318. {
  319. struct k_sigaction new_ka, old_ka;
  320. int ret;
  321. compat_sigset_t set32;
  322. /* XXX: Don't preclude handling different sized sigset_t's. */
  323. if (sigsetsize != sizeof(compat_sigset_t))
  324. return -EINVAL;
  325. if (act) {
  326. u32 u_handler, u_restorer;
  327. new_ka.ka_restorer = restorer;
  328. ret = get_user(u_handler, &act->sa_handler);
  329. new_ka.sa.sa_handler = compat_ptr(u_handler);
  330. ret |= __copy_from_user(&set32, &act->sa_mask, sizeof(compat_sigset_t));
  331. switch (_NSIG_WORDS) {
  332. case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6] | (((long)set32.sig[7]) << 32);
  333. case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4] | (((long)set32.sig[5]) << 32);
  334. case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2] | (((long)set32.sig[3]) << 32);
  335. case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0] | (((long)set32.sig[1]) << 32);
  336. }
  337. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  338. ret |= __get_user(u_restorer, &act->sa_restorer);
  339. new_ka.sa.sa_restorer = compat_ptr(u_restorer);
  340. if (ret)
  341. return -EFAULT;
  342. }
  343. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  344. if (!ret && oact) {
  345. switch (_NSIG_WORDS) {
  346. case 4: set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32); set32.sig[6] = old_ka.sa.sa_mask.sig[3];
  347. case 3: set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32); set32.sig[4] = old_ka.sa.sa_mask.sig[2];
  348. case 2: set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32); set32.sig[2] = old_ka.sa.sa_mask.sig[1];
  349. case 1: set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32); set32.sig[0] = old_ka.sa.sa_mask.sig[0];
  350. }
  351. ret = put_user(ptr_to_compat(old_ka.sa.sa_handler), &oact->sa_handler);
  352. ret |= __copy_to_user(&oact->sa_mask, &set32, sizeof(compat_sigset_t));
  353. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  354. ret |= __put_user(ptr_to_compat(old_ka.sa.sa_restorer), &oact->sa_restorer);
  355. if (ret)
  356. ret = -EFAULT;
  357. }
  358. return ret;
  359. }
  360. /*
  361. * sparc32_execve() executes a new program after the asm stub has set
  362. * things up for us. This should basically do what I want it to.
  363. */
  364. asmlinkage long sparc32_execve(struct pt_regs *regs)
  365. {
  366. int error, base = 0;
  367. char *filename;
  368. /* User register window flush is done by entry.S */
  369. /* Check for indirect call. */
  370. if ((u32)regs->u_regs[UREG_G1] == 0)
  371. base = 1;
  372. filename = getname(compat_ptr(regs->u_regs[base + UREG_I0]));
  373. error = PTR_ERR(filename);
  374. if (IS_ERR(filename))
  375. goto out;
  376. error = compat_do_execve(filename,
  377. compat_ptr(regs->u_regs[base + UREG_I1]),
  378. compat_ptr(regs->u_regs[base + UREG_I2]), regs);
  379. putname(filename);
  380. if (!error) {
  381. fprs_write(0);
  382. current_thread_info()->xfsr[0] = 0;
  383. current_thread_info()->fpsaved[0] = 0;
  384. regs->tstate &= ~TSTATE_PEF;
  385. }
  386. out:
  387. return error;
  388. }
  389. #ifdef CONFIG_MODULES
  390. asmlinkage long sys32_init_module(void __user *umod, u32 len,
  391. const char __user *uargs)
  392. {
  393. return sys_init_module(umod, len, uargs);
  394. }
  395. asmlinkage long sys32_delete_module(const char __user *name_user,
  396. unsigned int flags)
  397. {
  398. return sys_delete_module(name_user, flags);
  399. }
  400. #else /* CONFIG_MODULES */
  401. asmlinkage long sys32_init_module(const char __user *name_user,
  402. struct module __user *mod_user)
  403. {
  404. return -ENOSYS;
  405. }
  406. asmlinkage long sys32_delete_module(const char __user *name_user)
  407. {
  408. return -ENOSYS;
  409. }
  410. #endif /* CONFIG_MODULES */
  411. asmlinkage compat_ssize_t sys32_pread64(unsigned int fd,
  412. char __user *ubuf,
  413. compat_size_t count,
  414. unsigned long poshi,
  415. unsigned long poslo)
  416. {
  417. return sys_pread64(fd, ubuf, count, (poshi << 32) | poslo);
  418. }
  419. asmlinkage compat_ssize_t sys32_pwrite64(unsigned int fd,
  420. char __user *ubuf,
  421. compat_size_t count,
  422. unsigned long poshi,
  423. unsigned long poslo)
  424. {
  425. return sys_pwrite64(fd, ubuf, count, (poshi << 32) | poslo);
  426. }
  427. asmlinkage long compat_sys_readahead(int fd,
  428. unsigned long offhi,
  429. unsigned long offlo,
  430. compat_size_t count)
  431. {
  432. return sys_readahead(fd, (offhi << 32) | offlo, count);
  433. }
  434. long compat_sys_fadvise64(int fd,
  435. unsigned long offhi,
  436. unsigned long offlo,
  437. compat_size_t len, int advice)
  438. {
  439. return sys_fadvise64_64(fd, (offhi << 32) | offlo, len, advice);
  440. }
  441. long compat_sys_fadvise64_64(int fd,
  442. unsigned long offhi, unsigned long offlo,
  443. unsigned long lenhi, unsigned long lenlo,
  444. int advice)
  445. {
  446. return sys_fadvise64_64(fd,
  447. (offhi << 32) | offlo,
  448. (lenhi << 32) | lenlo,
  449. advice);
  450. }
  451. asmlinkage long compat_sys_sendfile(int out_fd, int in_fd,
  452. compat_off_t __user *offset,
  453. compat_size_t count)
  454. {
  455. mm_segment_t old_fs = get_fs();
  456. int ret;
  457. off_t of;
  458. if (offset && get_user(of, offset))
  459. return -EFAULT;
  460. set_fs(KERNEL_DS);
  461. ret = sys_sendfile(out_fd, in_fd,
  462. offset ? (off_t __user *) &of : NULL,
  463. count);
  464. set_fs(old_fs);
  465. if (offset && put_user(of, offset))
  466. return -EFAULT;
  467. return ret;
  468. }
  469. asmlinkage long compat_sys_sendfile64(int out_fd, int in_fd,
  470. compat_loff_t __user *offset,
  471. compat_size_t count)
  472. {
  473. mm_segment_t old_fs = get_fs();
  474. int ret;
  475. loff_t lof;
  476. if (offset && get_user(lof, offset))
  477. return -EFAULT;
  478. set_fs(KERNEL_DS);
  479. ret = sys_sendfile64(out_fd, in_fd,
  480. offset ? (loff_t __user *) &lof : NULL,
  481. count);
  482. set_fs(old_fs);
  483. if (offset && put_user(lof, offset))
  484. return -EFAULT;
  485. return ret;
  486. }
  487. /* This is just a version for 32-bit applications which does
  488. * not force O_LARGEFILE on.
  489. */
  490. asmlinkage long sparc32_open(const char __user *filename,
  491. int flags, int mode)
  492. {
  493. return do_sys_open(AT_FDCWD, filename, flags, mode);
  494. }
  495. extern unsigned long do_mremap(unsigned long addr,
  496. unsigned long old_len, unsigned long new_len,
  497. unsigned long flags, unsigned long new_addr);
  498. asmlinkage unsigned long sys32_mremap(unsigned long addr,
  499. unsigned long old_len, unsigned long new_len,
  500. unsigned long flags, u32 __new_addr)
  501. {
  502. unsigned long ret = -EINVAL;
  503. unsigned long new_addr = __new_addr;
  504. if (unlikely(sparc_mmap_check(addr, old_len)))
  505. goto out;
  506. if (unlikely(sparc_mmap_check(new_addr, new_len)))
  507. goto out;
  508. down_write(&current->mm->mmap_sem);
  509. ret = do_mremap(addr, old_len, new_len, flags, new_addr);
  510. up_write(&current->mm->mmap_sem);
  511. out:
  512. return ret;
  513. }
  514. struct __sysctl_args32 {
  515. u32 name;
  516. int nlen;
  517. u32 oldval;
  518. u32 oldlenp;
  519. u32 newval;
  520. u32 newlen;
  521. u32 __unused[4];
  522. };
  523. asmlinkage long sys32_sysctl(struct __sysctl_args32 __user *args)
  524. {
  525. #ifndef CONFIG_SYSCTL_SYSCALL
  526. return -ENOSYS;
  527. #else
  528. struct __sysctl_args32 tmp;
  529. int error;
  530. size_t oldlen, __user *oldlenp = NULL;
  531. unsigned long addr = (((unsigned long)&args->__unused[0]) + 7UL) & ~7UL;
  532. if (copy_from_user(&tmp, args, sizeof(tmp)))
  533. return -EFAULT;
  534. if (tmp.oldval && tmp.oldlenp) {
  535. /* Duh, this is ugly and might not work if sysctl_args
  536. is in read-only memory, but do_sysctl does indirectly
  537. a lot of uaccess in both directions and we'd have to
  538. basically copy the whole sysctl.c here, and
  539. glibc's __sysctl uses rw memory for the structure
  540. anyway. */
  541. if (get_user(oldlen, (u32 __user *)(unsigned long)tmp.oldlenp) ||
  542. put_user(oldlen, (size_t __user *)addr))
  543. return -EFAULT;
  544. oldlenp = (size_t __user *)addr;
  545. }
  546. lock_kernel();
  547. error = do_sysctl((int __user *)(unsigned long) tmp.name,
  548. tmp.nlen,
  549. (void __user *)(unsigned long) tmp.oldval,
  550. oldlenp,
  551. (void __user *)(unsigned long) tmp.newval,
  552. tmp.newlen);
  553. unlock_kernel();
  554. if (oldlenp) {
  555. if (!error) {
  556. if (get_user(oldlen, (size_t __user *)addr) ||
  557. put_user(oldlen, (u32 __user *)(unsigned long) tmp.oldlenp))
  558. error = -EFAULT;
  559. }
  560. if (copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
  561. error = -EFAULT;
  562. }
  563. return error;
  564. #endif
  565. }
  566. long sys32_lookup_dcookie(unsigned long cookie_high,
  567. unsigned long cookie_low,
  568. char __user *buf, size_t len)
  569. {
  570. return sys_lookup_dcookie((cookie_high << 32) | cookie_low,
  571. buf, len);
  572. }
  573. 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)
  574. {
  575. return sys_sync_file_range(fd,
  576. (off_high << 32) | off_low,
  577. (nb_high << 32) | nb_low,
  578. flags);
  579. }
  580. asmlinkage long compat_sys_fallocate(int fd, int mode, u32 offhi, u32 offlo,
  581. u32 lenhi, u32 lenlo)
  582. {
  583. return sys_fallocate(fd, mode, ((loff_t)offhi << 32) | offlo,
  584. ((loff_t)lenhi << 32) | lenlo);
  585. }