compat_linux.c 17 KB

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