sys_sparc32.c 18 KB

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