compat.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. /* Adjust unistd.h to provide 32-bit numbers and functions. */
  15. #define __SYSCALL_COMPAT
  16. #include <linux/compat.h>
  17. #include <linux/msg.h>
  18. #include <linux/syscalls.h>
  19. #include <linux/kdev_t.h>
  20. #include <linux/fs.h>
  21. #include <linux/fcntl.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/signal.h>
  24. #include <asm/syscalls.h>
  25. /*
  26. * Syscalls that take 64-bit numbers traditionally take them in 32-bit
  27. * "high" and "low" value parts on 32-bit architectures.
  28. * In principle, one could imagine passing some register arguments as
  29. * fully 64-bit on TILE-Gx in 32-bit mode, but it seems easier to
  30. * adapt the usual convention.
  31. */
  32. long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high)
  33. {
  34. return sys_truncate(filename, ((loff_t)high << 32) | low);
  35. }
  36. long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high)
  37. {
  38. return sys_ftruncate(fd, ((loff_t)high << 32) | low);
  39. }
  40. long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
  41. u32 dummy, u32 low, u32 high)
  42. {
  43. return sys_pread64(fd, ubuf, count, ((loff_t)high << 32) | low);
  44. }
  45. long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count,
  46. u32 dummy, u32 low, u32 high)
  47. {
  48. return sys_pwrite64(fd, ubuf, count, ((loff_t)high << 32) | low);
  49. }
  50. long compat_sys_lookup_dcookie(u32 low, u32 high, char __user *buf, size_t len)
  51. {
  52. return sys_lookup_dcookie(((loff_t)high << 32) | low, buf, len);
  53. }
  54. long compat_sys_sync_file_range2(int fd, unsigned int flags,
  55. u32 offset_lo, u32 offset_hi,
  56. u32 nbytes_lo, u32 nbytes_hi)
  57. {
  58. return sys_sync_file_range(fd, ((loff_t)offset_hi << 32) | offset_lo,
  59. ((loff_t)nbytes_hi << 32) | nbytes_lo,
  60. flags);
  61. }
  62. long compat_sys_fallocate(int fd, int mode,
  63. u32 offset_lo, u32 offset_hi,
  64. u32 len_lo, u32 len_hi)
  65. {
  66. return sys_fallocate(fd, mode, ((loff_t)offset_hi << 32) | offset_lo,
  67. ((loff_t)len_hi << 32) | len_lo);
  68. }
  69. long compat_sys_sched_rr_get_interval(compat_pid_t pid,
  70. struct compat_timespec __user *interval)
  71. {
  72. struct timespec t;
  73. int ret;
  74. mm_segment_t old_fs = get_fs();
  75. set_fs(KERNEL_DS);
  76. ret = sys_sched_rr_get_interval(pid,
  77. (struct timespec __force __user *)&t);
  78. set_fs(old_fs);
  79. if (put_compat_timespec(&t, interval))
  80. return -EFAULT;
  81. return ret;
  82. }
  83. /*
  84. * The usual compat_sys_msgsnd() and _msgrcv() seem to be assuming
  85. * some different calling convention than our normal 32-bit tile code.
  86. */
  87. /* Already defined in ipc/compat.c, but we need it here. */
  88. struct compat_msgbuf {
  89. compat_long_t mtype;
  90. char mtext[1];
  91. };
  92. long tile_compat_sys_msgsnd(int msqid,
  93. struct compat_msgbuf __user *msgp,
  94. size_t msgsz, int msgflg)
  95. {
  96. compat_long_t mtype;
  97. if (get_user(mtype, &msgp->mtype))
  98. return -EFAULT;
  99. return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg);
  100. }
  101. long tile_compat_sys_msgrcv(int msqid,
  102. struct compat_msgbuf __user *msgp,
  103. size_t msgsz, long msgtyp, int msgflg)
  104. {
  105. long err, mtype;
  106. err = do_msgrcv(msqid, &mtype, msgp->mtext, msgsz, msgtyp, msgflg);
  107. if (err < 0)
  108. goto out;
  109. if (put_user(mtype, &msgp->mtype))
  110. err = -EFAULT;
  111. out:
  112. return err;
  113. }
  114. /* Provide the compat syscall number to call mapping. */
  115. #undef __SYSCALL
  116. #define __SYSCALL(nr, call) [nr] = (call),
  117. /* The generic versions of these don't work for Tile. */
  118. #define compat_sys_msgrcv tile_compat_sys_msgrcv
  119. #define compat_sys_msgsnd tile_compat_sys_msgsnd
  120. /* See comments in sys.c */
  121. #define compat_sys_fadvise64_64 sys32_fadvise64_64
  122. #define compat_sys_readahead sys32_readahead
  123. /* Call the trampolines to manage pt_regs where necessary. */
  124. #define compat_sys_execve _compat_sys_execve
  125. #define compat_sys_sigaltstack _compat_sys_sigaltstack
  126. #define compat_sys_rt_sigreturn _compat_sys_rt_sigreturn
  127. #define sys_clone _sys_clone
  128. /*
  129. * Note that we can't include <linux/unistd.h> here since the header
  130. * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
  131. */
  132. void *compat_sys_call_table[__NR_syscalls] = {
  133. [0 ... __NR_syscalls-1] = sys_ni_syscall,
  134. #include <asm/unistd.h>
  135. };