compat.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/smp_lock.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/signal.h>
  25. #include <asm/syscalls.h>
  26. /*
  27. * Syscalls that take 64-bit numbers traditionally take them in 32-bit
  28. * "high" and "low" value parts on 32-bit architectures.
  29. * In principle, one could imagine passing some register arguments as
  30. * fully 64-bit on TILE-Gx in 32-bit mode, but it seems easier to
  31. * adapt the usual convention.
  32. */
  33. long compat_sys_truncate64(char __user *filename, u32 dummy, u32 low, u32 high)
  34. {
  35. return sys_truncate(filename, ((loff_t)high << 32) | low);
  36. }
  37. long compat_sys_ftruncate64(unsigned int fd, u32 dummy, u32 low, u32 high)
  38. {
  39. return sys_ftruncate(fd, ((loff_t)high << 32) | low);
  40. }
  41. long compat_sys_pread64(unsigned int fd, char __user *ubuf, size_t count,
  42. u32 dummy, u32 low, u32 high)
  43. {
  44. return sys_pread64(fd, ubuf, count, ((loff_t)high << 32) | low);
  45. }
  46. long compat_sys_pwrite64(unsigned int fd, char __user *ubuf, size_t count,
  47. u32 dummy, u32 low, u32 high)
  48. {
  49. return sys_pwrite64(fd, ubuf, count, ((loff_t)high << 32) | low);
  50. }
  51. long compat_sys_lookup_dcookie(u32 low, u32 high, char __user *buf, size_t len)
  52. {
  53. return sys_lookup_dcookie(((loff_t)high << 32) | low, buf, len);
  54. }
  55. long compat_sys_sync_file_range2(int fd, unsigned int flags,
  56. u32 offset_lo, u32 offset_hi,
  57. u32 nbytes_lo, u32 nbytes_hi)
  58. {
  59. return sys_sync_file_range(fd, ((loff_t)offset_hi << 32) | offset_lo,
  60. ((loff_t)nbytes_hi << 32) | nbytes_lo,
  61. flags);
  62. }
  63. long compat_sys_fallocate(int fd, int mode,
  64. u32 offset_lo, u32 offset_hi,
  65. u32 len_lo, u32 len_hi)
  66. {
  67. return sys_fallocate(fd, mode, ((loff_t)offset_hi << 32) | offset_lo,
  68. ((loff_t)len_hi << 32) | len_lo);
  69. }
  70. long compat_sys_sched_rr_get_interval(compat_pid_t pid,
  71. struct compat_timespec __user *interval)
  72. {
  73. struct timespec t;
  74. int ret;
  75. mm_segment_t old_fs = get_fs();
  76. set_fs(KERNEL_DS);
  77. ret = sys_sched_rr_get_interval(pid,
  78. (struct timespec __force __user *)&t);
  79. set_fs(old_fs);
  80. if (put_compat_timespec(&t, interval))
  81. return -EFAULT;
  82. return ret;
  83. }
  84. /*
  85. * The usual compat_sys_msgsnd() and _msgrcv() seem to be assuming
  86. * some different calling convention than our normal 32-bit tile code.
  87. */
  88. /* Already defined in ipc/compat.c, but we need it here. */
  89. struct compat_msgbuf {
  90. compat_long_t mtype;
  91. char mtext[1];
  92. };
  93. long tile_compat_sys_msgsnd(int msqid,
  94. struct compat_msgbuf __user *msgp,
  95. size_t msgsz, int msgflg)
  96. {
  97. compat_long_t mtype;
  98. if (get_user(mtype, &msgp->mtype))
  99. return -EFAULT;
  100. return do_msgsnd(msqid, mtype, msgp->mtext, msgsz, msgflg);
  101. }
  102. long tile_compat_sys_msgrcv(int msqid,
  103. struct compat_msgbuf __user *msgp,
  104. size_t msgsz, long msgtyp, int msgflg)
  105. {
  106. long err, mtype;
  107. err = do_msgrcv(msqid, &mtype, msgp->mtext, msgsz, msgtyp, msgflg);
  108. if (err < 0)
  109. goto out;
  110. if (put_user(mtype, &msgp->mtype))
  111. err = -EFAULT;
  112. out:
  113. return err;
  114. }
  115. /* Provide the compat syscall number to call mapping. */
  116. #undef __SYSCALL
  117. #define __SYSCALL(nr, call) [nr] = (compat_##call),
  118. /* The generic versions of these don't work for Tile. */
  119. #define compat_sys_msgrcv tile_compat_sys_msgrcv
  120. #define compat_sys_msgsnd tile_compat_sys_msgsnd
  121. /* See comments in sys.c */
  122. #define compat_sys_fadvise64 sys32_fadvise64
  123. #define compat_sys_fadvise64_64 sys32_fadvise64_64
  124. #define compat_sys_readahead sys32_readahead
  125. #define compat_sys_sync_file_range compat_sys_sync_file_range2
  126. /* The native 64-bit "struct stat" matches the 32-bit "struct stat64". */
  127. #define compat_sys_stat64 sys_newstat
  128. #define compat_sys_lstat64 sys_newlstat
  129. #define compat_sys_fstat64 sys_newfstat
  130. #define compat_sys_fstatat64 sys_newfstatat
  131. /* Pass full 64-bit values through ptrace. */
  132. #define compat_sys_ptrace tile_compat_sys_ptrace
  133. /*
  134. * Note that we can't include <linux/unistd.h> here since the header
  135. * guard will defeat us; <asm/unistd.h> checks for __SYSCALL as well.
  136. */
  137. void *compat_sys_call_table[__NR_syscalls] = {
  138. [0 ... __NR_syscalls-1] = sys_ni_syscall,
  139. #include <asm/unistd.h>
  140. };