compat_linux.c 17 KB

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