compat_linux.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * S390 version
  3. * Copyright IBM Corp. 2000
  4. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  5. * Gerhard Tonn (ton@de.ibm.com)
  6. * Thomas Spatzier (tspat@de.ibm.com)
  7. *
  8. * Conversion between 31bit and 64bit native syscalls.
  9. *
  10. * Heavily inspired by the 32-bit Sparc compat code which is
  11. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  12. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/sched.h>
  17. #include <linux/fs.h>
  18. #include <linux/mm.h>
  19. #include <linux/file.h>
  20. #include <linux/signal.h>
  21. #include <linux/resource.h>
  22. #include <linux/times.h>
  23. #include <linux/smp.h>
  24. #include <linux/sem.h>
  25. #include <linux/msg.h>
  26. #include <linux/shm.h>
  27. #include <linux/uio.h>
  28. #include <linux/quota.h>
  29. #include <linux/module.h>
  30. #include <linux/poll.h>
  31. #include <linux/personality.h>
  32. #include <linux/stat.h>
  33. #include <linux/filter.h>
  34. #include <linux/highmem.h>
  35. #include <linux/highuid.h>
  36. #include <linux/mman.h>
  37. #include <linux/ipv6.h>
  38. #include <linux/in.h>
  39. #include <linux/icmpv6.h>
  40. #include <linux/syscalls.h>
  41. #include <linux/sysctl.h>
  42. #include <linux/binfmts.h>
  43. #include <linux/capability.h>
  44. #include <linux/compat.h>
  45. #include <linux/vfs.h>
  46. #include <linux/ptrace.h>
  47. #include <linux/fadvise.h>
  48. #include <linux/ipc.h>
  49. #include <linux/slab.h>
  50. #include <asm/types.h>
  51. #include <asm/uaccess.h>
  52. #include <net/scm.h>
  53. #include <net/sock.h>
  54. #include "compat_linux.h"
  55. u32 psw32_user_bits = PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT |
  56. PSW32_DEFAULT_KEY | PSW32_MASK_BASE | PSW32_MASK_MCHECK |
  57. PSW32_MASK_PSTATE | PSW32_ASC_HOME;
  58. /* For this source file, we want overflow handling. */
  59. #undef high2lowuid
  60. #undef high2lowgid
  61. #undef low2highuid
  62. #undef low2highgid
  63. #undef SET_UID16
  64. #undef SET_GID16
  65. #undef NEW_TO_OLD_UID
  66. #undef NEW_TO_OLD_GID
  67. #undef SET_OLDSTAT_UID
  68. #undef SET_OLDSTAT_GID
  69. #undef SET_STAT_UID
  70. #undef SET_STAT_GID
  71. #define high2lowuid(uid) ((uid) > 65535) ? (u16)overflowuid : (u16)(uid)
  72. #define high2lowgid(gid) ((gid) > 65535) ? (u16)overflowgid : (u16)(gid)
  73. #define low2highuid(uid) ((uid) == (u16)-1) ? (uid_t)-1 : (uid_t)(uid)
  74. #define low2highgid(gid) ((gid) == (u16)-1) ? (gid_t)-1 : (gid_t)(gid)
  75. #define SET_UID16(var, uid) var = high2lowuid(uid)
  76. #define SET_GID16(var, gid) var = high2lowgid(gid)
  77. #define NEW_TO_OLD_UID(uid) high2lowuid(uid)
  78. #define NEW_TO_OLD_GID(gid) high2lowgid(gid)
  79. #define SET_OLDSTAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
  80. #define SET_OLDSTAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
  81. #define SET_STAT_UID(stat, uid) (stat).st_uid = high2lowuid(uid)
  82. #define SET_STAT_GID(stat, gid) (stat).st_gid = high2lowgid(gid)
  83. asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
  84. {
  85. return sys_chown(filename, low2highuid(user), low2highgid(group));
  86. }
  87. asmlinkage long sys32_lchown16(const char __user * filename, u16 user, u16 group)
  88. {
  89. return sys_lchown(filename, low2highuid(user), low2highgid(group));
  90. }
  91. asmlinkage long sys32_fchown16(unsigned int fd, u16 user, u16 group)
  92. {
  93. return sys_fchown(fd, low2highuid(user), low2highgid(group));
  94. }
  95. asmlinkage long sys32_setregid16(u16 rgid, u16 egid)
  96. {
  97. return sys_setregid(low2highgid(rgid), low2highgid(egid));
  98. }
  99. asmlinkage long sys32_setgid16(u16 gid)
  100. {
  101. return sys_setgid((gid_t)gid);
  102. }
  103. asmlinkage long sys32_setreuid16(u16 ruid, u16 euid)
  104. {
  105. return sys_setreuid(low2highuid(ruid), low2highuid(euid));
  106. }
  107. asmlinkage long sys32_setuid16(u16 uid)
  108. {
  109. return sys_setuid((uid_t)uid);
  110. }
  111. asmlinkage long sys32_setresuid16(u16 ruid, u16 euid, u16 suid)
  112. {
  113. return sys_setresuid(low2highuid(ruid), low2highuid(euid),
  114. low2highuid(suid));
  115. }
  116. asmlinkage long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
  117. {
  118. int retval;
  119. if (!(retval = put_user(high2lowuid(current->cred->uid), ruid)) &&
  120. !(retval = put_user(high2lowuid(current->cred->euid), euid)))
  121. retval = put_user(high2lowuid(current->cred->suid), suid);
  122. return retval;
  123. }
  124. asmlinkage long sys32_setresgid16(u16 rgid, u16 egid, u16 sgid)
  125. {
  126. return sys_setresgid(low2highgid(rgid), low2highgid(egid),
  127. low2highgid(sgid));
  128. }
  129. asmlinkage long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
  130. {
  131. int retval;
  132. if (!(retval = put_user(high2lowgid(current->cred->gid), rgid)) &&
  133. !(retval = put_user(high2lowgid(current->cred->egid), egid)))
  134. retval = put_user(high2lowgid(current->cred->sgid), sgid);
  135. return retval;
  136. }
  137. asmlinkage long sys32_setfsuid16(u16 uid)
  138. {
  139. return sys_setfsuid((uid_t)uid);
  140. }
  141. asmlinkage long sys32_setfsgid16(u16 gid)
  142. {
  143. return sys_setfsgid((gid_t)gid);
  144. }
  145. static int groups16_to_user(u16 __user *grouplist, struct group_info *group_info)
  146. {
  147. struct user_namespace *user_ns = current_user_ns();
  148. int i;
  149. u16 group;
  150. kgid_t kgid;
  151. for (i = 0; i < group_info->ngroups; i++) {
  152. kgid = GROUP_AT(group_info, i);
  153. group = (u16)from_kgid_munged(user_ns, kgid);
  154. if (put_user(group, grouplist+i))
  155. return -EFAULT;
  156. }
  157. return 0;
  158. }
  159. static int groups16_from_user(struct group_info *group_info, u16 __user *grouplist)
  160. {
  161. struct user_namespace *user_ns = current_user_ns();
  162. int i;
  163. u16 group;
  164. kgid_t kgid;
  165. for (i = 0; i < group_info->ngroups; i++) {
  166. if (get_user(group, grouplist+i))
  167. return -EFAULT;
  168. kgid = make_kgid(user_ns, (gid_t)group);
  169. if (!gid_valid(kgid))
  170. return -EINVAL;
  171. GROUP_AT(group_info, i) = kgid;
  172. }
  173. return 0;
  174. }
  175. asmlinkage long sys32_getgroups16(int gidsetsize, u16 __user *grouplist)
  176. {
  177. int i;
  178. if (gidsetsize < 0)
  179. return -EINVAL;
  180. get_group_info(current->cred->group_info);
  181. i = current->cred->group_info->ngroups;
  182. if (gidsetsize) {
  183. if (i > gidsetsize) {
  184. i = -EINVAL;
  185. goto out;
  186. }
  187. if (groups16_to_user(grouplist, current->cred->group_info)) {
  188. i = -EFAULT;
  189. goto out;
  190. }
  191. }
  192. out:
  193. put_group_info(current->cred->group_info);
  194. return i;
  195. }
  196. asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
  197. {
  198. struct group_info *group_info;
  199. int retval;
  200. if (!capable(CAP_SETGID))
  201. return -EPERM;
  202. if ((unsigned)gidsetsize > NGROUPS_MAX)
  203. return -EINVAL;
  204. group_info = groups_alloc(gidsetsize);
  205. if (!group_info)
  206. return -ENOMEM;
  207. retval = groups16_from_user(group_info, grouplist);
  208. if (retval) {
  209. put_group_info(group_info);
  210. return retval;
  211. }
  212. retval = set_current_groups(group_info);
  213. put_group_info(group_info);
  214. return retval;
  215. }
  216. asmlinkage long sys32_getuid16(void)
  217. {
  218. return high2lowuid(current->cred->uid);
  219. }
  220. asmlinkage long sys32_geteuid16(void)
  221. {
  222. return high2lowuid(current->cred->euid);
  223. }
  224. asmlinkage long sys32_getgid16(void)
  225. {
  226. return high2lowgid(current->cred->gid);
  227. }
  228. asmlinkage long sys32_getegid16(void)
  229. {
  230. return high2lowgid(current->cred->egid);
  231. }
  232. /*
  233. * sys32_ipc() is the de-multiplexer for the SysV IPC calls in 32bit emulation.
  234. *
  235. * This is really horribly ugly.
  236. */
  237. #ifdef CONFIG_SYSVIPC
  238. asmlinkage long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
  239. {
  240. if (call >> 16) /* hack for backward compatibility */
  241. return -EINVAL;
  242. switch (call) {
  243. case SEMTIMEDOP:
  244. return compat_sys_semtimedop(first, compat_ptr(ptr),
  245. second, compat_ptr(third));
  246. case SEMOP:
  247. /* struct sembuf is the same on 32 and 64bit :)) */
  248. return sys_semtimedop(first, compat_ptr(ptr),
  249. second, NULL);
  250. case SEMGET:
  251. return sys_semget(first, second, third);
  252. case SEMCTL:
  253. return compat_sys_semctl(first, second, third,
  254. compat_ptr(ptr));
  255. case MSGSND:
  256. return compat_sys_msgsnd(first, second, third,
  257. compat_ptr(ptr));
  258. case MSGRCV:
  259. return compat_sys_msgrcv(first, second, 0, third,
  260. 0, compat_ptr(ptr));
  261. case MSGGET:
  262. return sys_msgget((key_t) first, second);
  263. case MSGCTL:
  264. return compat_sys_msgctl(first, second, compat_ptr(ptr));
  265. case SHMAT:
  266. return compat_sys_shmat(first, second, third,
  267. 0, compat_ptr(ptr));
  268. case SHMDT:
  269. return sys_shmdt(compat_ptr(ptr));
  270. case SHMGET:
  271. return sys_shmget(first, (unsigned)second, third);
  272. case SHMCTL:
  273. return compat_sys_shmctl(first, second, compat_ptr(ptr));
  274. }
  275. return -ENOSYS;
  276. }
  277. #endif
  278. asmlinkage long sys32_truncate64(const char __user * path, unsigned long high, unsigned long low)
  279. {
  280. if ((int)high < 0)
  281. return -EINVAL;
  282. else
  283. return sys_truncate(path, (high << 32) | low);
  284. }
  285. asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low)
  286. {
  287. if ((int)high < 0)
  288. return -EINVAL;
  289. else
  290. return sys_ftruncate(fd, (high << 32) | low);
  291. }
  292. asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
  293. struct compat_timespec __user *interval)
  294. {
  295. struct timespec t;
  296. int ret;
  297. mm_segment_t old_fs = get_fs ();
  298. set_fs (KERNEL_DS);
  299. ret = sys_sched_rr_get_interval(pid,
  300. (struct timespec __force __user *) &t);
  301. set_fs (old_fs);
  302. if (put_compat_timespec(&t, interval))
  303. return -EFAULT;
  304. return ret;
  305. }
  306. asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
  307. compat_sigset_t __user *oset, size_t sigsetsize)
  308. {
  309. sigset_t s;
  310. compat_sigset_t s32;
  311. int ret;
  312. mm_segment_t old_fs = get_fs();
  313. if (set) {
  314. if (copy_from_user (&s32, set, sizeof(compat_sigset_t)))
  315. return -EFAULT;
  316. s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  317. }
  318. set_fs (KERNEL_DS);
  319. ret = sys_rt_sigprocmask(how,
  320. set ? (sigset_t __force __user *) &s : NULL,
  321. oset ? (sigset_t __force __user *) &s : NULL,
  322. sigsetsize);
  323. set_fs (old_fs);
  324. if (ret) return ret;
  325. if (oset) {
  326. s32.sig[1] = (s.sig[0] >> 32);
  327. s32.sig[0] = s.sig[0];
  328. if (copy_to_user (oset, &s32, sizeof(compat_sigset_t)))
  329. return -EFAULT;
  330. }
  331. return 0;
  332. }
  333. asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
  334. size_t sigsetsize)
  335. {
  336. sigset_t s;
  337. compat_sigset_t s32;
  338. int ret;
  339. mm_segment_t old_fs = get_fs();
  340. set_fs (KERNEL_DS);
  341. ret = sys_rt_sigpending((sigset_t __force __user *) &s, sigsetsize);
  342. set_fs (old_fs);
  343. if (!ret) {
  344. s32.sig[1] = (s.sig[0] >> 32);
  345. s32.sig[0] = s.sig[0];
  346. if (copy_to_user (set, &s32, sizeof(compat_sigset_t)))
  347. return -EFAULT;
  348. }
  349. return ret;
  350. }
  351. asmlinkage long
  352. sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
  353. {
  354. siginfo_t info;
  355. int ret;
  356. mm_segment_t old_fs = get_fs();
  357. if (copy_siginfo_from_user32(&info, uinfo))
  358. return -EFAULT;
  359. set_fs (KERNEL_DS);
  360. ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force __user *) &info);
  361. set_fs (old_fs);
  362. return ret;
  363. }
  364. /*
  365. * sys32_execve() executes a new program after the asm stub has set
  366. * things up for us. This should basically do what I want it to.
  367. */
  368. asmlinkage long sys32_execve(const char __user *name, compat_uptr_t __user *argv,
  369. compat_uptr_t __user *envp)
  370. {
  371. struct pt_regs *regs = task_pt_regs(current);
  372. char *filename;
  373. long rc;
  374. filename = getname(name);
  375. rc = PTR_ERR(filename);
  376. if (IS_ERR(filename))
  377. return rc;
  378. rc = compat_do_execve(filename, argv, envp, regs);
  379. if (rc)
  380. goto out;
  381. current->thread.fp_regs.fpc=0;
  382. asm volatile("sfpc %0,0" : : "d" (0));
  383. rc = regs->gprs[2];
  384. out:
  385. putname(filename);
  386. return rc;
  387. }
  388. asmlinkage long sys32_pread64(unsigned int fd, char __user *ubuf,
  389. size_t count, u32 poshi, u32 poslo)
  390. {
  391. if ((compat_ssize_t) count < 0)
  392. return -EINVAL;
  393. return sys_pread64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
  394. }
  395. asmlinkage long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
  396. size_t count, u32 poshi, u32 poslo)
  397. {
  398. if ((compat_ssize_t) count < 0)
  399. return -EINVAL;
  400. return sys_pwrite64(fd, ubuf, count, ((loff_t)AA(poshi) << 32) | AA(poslo));
  401. }
  402. asmlinkage compat_ssize_t sys32_readahead(int fd, u32 offhi, u32 offlo, s32 count)
  403. {
  404. return sys_readahead(fd, ((loff_t)AA(offhi) << 32) | AA(offlo), count);
  405. }
  406. asmlinkage long sys32_sendfile(int out_fd, int in_fd, compat_off_t __user *offset, size_t count)
  407. {
  408. mm_segment_t old_fs = get_fs();
  409. int ret;
  410. off_t of;
  411. if (offset && get_user(of, offset))
  412. return -EFAULT;
  413. set_fs(KERNEL_DS);
  414. ret = sys_sendfile(out_fd, in_fd,
  415. offset ? (off_t __force __user *) &of : NULL, count);
  416. set_fs(old_fs);
  417. if (offset && put_user(of, offset))
  418. return -EFAULT;
  419. return ret;
  420. }
  421. asmlinkage long sys32_sendfile64(int out_fd, int in_fd,
  422. compat_loff_t __user *offset, s32 count)
  423. {
  424. mm_segment_t old_fs = get_fs();
  425. int ret;
  426. loff_t lof;
  427. if (offset && get_user(lof, offset))
  428. return -EFAULT;
  429. set_fs(KERNEL_DS);
  430. ret = sys_sendfile64(out_fd, in_fd,
  431. offset ? (loff_t __force __user *) &lof : NULL,
  432. count);
  433. set_fs(old_fs);
  434. if (offset && put_user(lof, offset))
  435. return -EFAULT;
  436. return ret;
  437. }
  438. struct stat64_emu31 {
  439. unsigned long long st_dev;
  440. unsigned int __pad1;
  441. #define STAT64_HAS_BROKEN_ST_INO 1
  442. u32 __st_ino;
  443. unsigned int st_mode;
  444. unsigned int st_nlink;
  445. u32 st_uid;
  446. u32 st_gid;
  447. unsigned long long st_rdev;
  448. unsigned int __pad3;
  449. long st_size;
  450. u32 st_blksize;
  451. unsigned char __pad4[4];
  452. u32 __pad5; /* future possible st_blocks high bits */
  453. u32 st_blocks; /* Number 512-byte blocks allocated. */
  454. u32 st_atime;
  455. u32 __pad6;
  456. u32 st_mtime;
  457. u32 __pad7;
  458. u32 st_ctime;
  459. u32 __pad8; /* will be high 32 bits of ctime someday */
  460. unsigned long st_ino;
  461. };
  462. static int cp_stat64(struct stat64_emu31 __user *ubuf, struct kstat *stat)
  463. {
  464. struct stat64_emu31 tmp;
  465. memset(&tmp, 0, sizeof(tmp));
  466. tmp.st_dev = huge_encode_dev(stat->dev);
  467. tmp.st_ino = stat->ino;
  468. tmp.__st_ino = (u32)stat->ino;
  469. tmp.st_mode = stat->mode;
  470. tmp.st_nlink = (unsigned int)stat->nlink;
  471. tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
  472. tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
  473. tmp.st_rdev = huge_encode_dev(stat->rdev);
  474. tmp.st_size = stat->size;
  475. tmp.st_blksize = (u32)stat->blksize;
  476. tmp.st_blocks = (u32)stat->blocks;
  477. tmp.st_atime = (u32)stat->atime.tv_sec;
  478. tmp.st_mtime = (u32)stat->mtime.tv_sec;
  479. tmp.st_ctime = (u32)stat->ctime.tv_sec;
  480. return copy_to_user(ubuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
  481. }
  482. asmlinkage long sys32_stat64(const char __user * filename, struct stat64_emu31 __user * statbuf)
  483. {
  484. struct kstat stat;
  485. int ret = vfs_stat(filename, &stat);
  486. if (!ret)
  487. ret = cp_stat64(statbuf, &stat);
  488. return ret;
  489. }
  490. asmlinkage long sys32_lstat64(const char __user * filename, struct stat64_emu31 __user * statbuf)
  491. {
  492. struct kstat stat;
  493. int ret = vfs_lstat(filename, &stat);
  494. if (!ret)
  495. ret = cp_stat64(statbuf, &stat);
  496. return ret;
  497. }
  498. asmlinkage long sys32_fstat64(unsigned long fd, struct stat64_emu31 __user * statbuf)
  499. {
  500. struct kstat stat;
  501. int ret = vfs_fstat(fd, &stat);
  502. if (!ret)
  503. ret = cp_stat64(statbuf, &stat);
  504. return ret;
  505. }
  506. asmlinkage long sys32_fstatat64(unsigned int dfd, const char __user *filename,
  507. struct stat64_emu31 __user* statbuf, int flag)
  508. {
  509. struct kstat stat;
  510. int error;
  511. error = vfs_fstatat(dfd, filename, &stat, flag);
  512. if (error)
  513. return error;
  514. return cp_stat64(statbuf, &stat);
  515. }
  516. /*
  517. * Linux/i386 didn't use to be able to handle more than
  518. * 4 system call parameters, so these system calls used a memory
  519. * block for parameter passing..
  520. */
  521. struct mmap_arg_struct_emu31 {
  522. compat_ulong_t addr;
  523. compat_ulong_t len;
  524. compat_ulong_t prot;
  525. compat_ulong_t flags;
  526. compat_ulong_t fd;
  527. compat_ulong_t offset;
  528. };
  529. asmlinkage unsigned long old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
  530. {
  531. struct mmap_arg_struct_emu31 a;
  532. if (copy_from_user(&a, arg, sizeof(a)))
  533. return -EFAULT;
  534. if (a.offset & ~PAGE_MASK)
  535. return -EINVAL;
  536. a.addr = (unsigned long) compat_ptr(a.addr);
  537. return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd,
  538. a.offset >> PAGE_SHIFT);
  539. }
  540. asmlinkage long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
  541. {
  542. struct mmap_arg_struct_emu31 a;
  543. if (copy_from_user(&a, arg, sizeof(a)))
  544. return -EFAULT;
  545. a.addr = (unsigned long) compat_ptr(a.addr);
  546. return sys_mmap_pgoff(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  547. }
  548. asmlinkage long sys32_read(unsigned int fd, char __user * buf, size_t count)
  549. {
  550. if ((compat_ssize_t) count < 0)
  551. return -EINVAL;
  552. return sys_read(fd, buf, count);
  553. }
  554. asmlinkage long sys32_write(unsigned int fd, const char __user * buf, size_t count)
  555. {
  556. if ((compat_ssize_t) count < 0)
  557. return -EINVAL;
  558. return sys_write(fd, buf, count);
  559. }
  560. /*
  561. * 31 bit emulation wrapper functions for sys_fadvise64/fadvise64_64.
  562. * These need to rewrite the advise values for POSIX_FADV_{DONTNEED,NOREUSE}
  563. * because the 31 bit values differ from the 64 bit values.
  564. */
  565. asmlinkage long
  566. sys32_fadvise64(int fd, loff_t offset, size_t len, int advise)
  567. {
  568. if (advise == 4)
  569. advise = POSIX_FADV_DONTNEED;
  570. else if (advise == 5)
  571. advise = POSIX_FADV_NOREUSE;
  572. return sys_fadvise64(fd, offset, len, advise);
  573. }
  574. struct fadvise64_64_args {
  575. int fd;
  576. long long offset;
  577. long long len;
  578. int advice;
  579. };
  580. asmlinkage long
  581. sys32_fadvise64_64(struct fadvise64_64_args __user *args)
  582. {
  583. struct fadvise64_64_args a;
  584. if ( copy_from_user(&a, args, sizeof(a)) )
  585. return -EFAULT;
  586. if (a.advice == 4)
  587. a.advice = POSIX_FADV_DONTNEED;
  588. else if (a.advice == 5)
  589. a.advice = POSIX_FADV_NOREUSE;
  590. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  591. }