sys_parisc.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * PARISC specific syscalls
  3. *
  4. * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
  5. * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
  6. * Copyright (C) 2001 Thomas Bogendoerfer <tsbogend at parisc-linux.org>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <asm/uaccess.h>
  24. #include <linux/file.h>
  25. #include <linux/fs.h>
  26. #include <linux/linkage.h>
  27. #include <linux/mm.h>
  28. #include <linux/mman.h>
  29. #include <linux/shm.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/syscalls.h>
  32. #include <linux/utsname.h>
  33. #include <linux/personality.h>
  34. int sys_pipe(int __user *fildes)
  35. {
  36. int fd[2];
  37. int error;
  38. error = do_pipe(fd);
  39. if (!error) {
  40. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  41. error = -EFAULT;
  42. }
  43. return error;
  44. }
  45. static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
  46. {
  47. struct vm_area_struct *vma;
  48. addr = PAGE_ALIGN(addr);
  49. for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
  50. /* At this point: (!vma || addr < vma->vm_end). */
  51. if (TASK_SIZE - len < addr)
  52. return -ENOMEM;
  53. if (!vma || addr + len <= vma->vm_start)
  54. return addr;
  55. addr = vma->vm_end;
  56. }
  57. }
  58. #define DCACHE_ALIGN(addr) (((addr) + (SHMLBA - 1)) &~ (SHMLBA - 1))
  59. /*
  60. * We need to know the offset to use. Old scheme was to look for
  61. * existing mapping and use the same offset. New scheme is to use the
  62. * address of the kernel data structure as the seed for the offset.
  63. * We'll see how that works...
  64. *
  65. * The mapping is cacheline aligned, so there's no information in the bottom
  66. * few bits of the address. We're looking for 10 bits (4MB / 4k), so let's
  67. * drop the bottom 8 bits and use bits 8-17.
  68. */
  69. static int get_offset(struct address_space *mapping)
  70. {
  71. int offset = (unsigned long) mapping << (PAGE_SHIFT - 8);
  72. return offset & 0x3FF000;
  73. }
  74. static unsigned long get_shared_area(struct address_space *mapping,
  75. unsigned long addr, unsigned long len, unsigned long pgoff)
  76. {
  77. struct vm_area_struct *vma;
  78. int offset = mapping ? get_offset(mapping) : 0;
  79. addr = DCACHE_ALIGN(addr - offset) + offset;
  80. for (vma = find_vma(current->mm, addr); ; vma = vma->vm_next) {
  81. /* At this point: (!vma || addr < vma->vm_end). */
  82. if (TASK_SIZE - len < addr)
  83. return -ENOMEM;
  84. if (!vma || addr + len <= vma->vm_start)
  85. return addr;
  86. addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
  87. if (addr < vma->vm_end) /* handle wraparound */
  88. return -ENOMEM;
  89. }
  90. }
  91. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  92. unsigned long len, unsigned long pgoff, unsigned long flags)
  93. {
  94. if (len > TASK_SIZE)
  95. return -ENOMEM;
  96. /* Might want to check for cache aliasing issues for MAP_FIXED case
  97. * like ARM or MIPS ??? --BenH.
  98. */
  99. if (flags & MAP_FIXED)
  100. return addr;
  101. if (!addr)
  102. addr = TASK_UNMAPPED_BASE;
  103. if (filp) {
  104. addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
  105. } else if(flags & MAP_SHARED) {
  106. addr = get_shared_area(NULL, addr, len, pgoff);
  107. } else {
  108. addr = get_unshared_area(addr, len);
  109. }
  110. return addr;
  111. }
  112. static unsigned long do_mmap2(unsigned long addr, unsigned long len,
  113. unsigned long prot, unsigned long flags, unsigned long fd,
  114. unsigned long pgoff)
  115. {
  116. struct file * file = NULL;
  117. unsigned long error = -EBADF;
  118. if (!(flags & MAP_ANONYMOUS)) {
  119. file = fget(fd);
  120. if (!file)
  121. goto out;
  122. }
  123. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  124. down_write(&current->mm->mmap_sem);
  125. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  126. up_write(&current->mm->mmap_sem);
  127. if (file != NULL)
  128. fput(file);
  129. out:
  130. return error;
  131. }
  132. asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len,
  133. unsigned long prot, unsigned long flags, unsigned long fd,
  134. unsigned long pgoff)
  135. {
  136. /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE
  137. we have. */
  138. return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12));
  139. }
  140. asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len,
  141. unsigned long prot, unsigned long flags, unsigned long fd,
  142. unsigned long offset)
  143. {
  144. if (!(offset & ~PAGE_MASK)) {
  145. return do_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  146. } else {
  147. return -EINVAL;
  148. }
  149. }
  150. /* Fucking broken ABI */
  151. #ifdef CONFIG_64BIT
  152. asmlinkage long parisc_truncate64(const char __user * path,
  153. unsigned int high, unsigned int low)
  154. {
  155. return sys_truncate(path, (long)high << 32 | low);
  156. }
  157. asmlinkage long parisc_ftruncate64(unsigned int fd,
  158. unsigned int high, unsigned int low)
  159. {
  160. return sys_ftruncate(fd, (long)high << 32 | low);
  161. }
  162. /* stubs for the benefit of the syscall_table since truncate64 and truncate
  163. * are identical on LP64 */
  164. asmlinkage long sys_truncate64(const char __user * path, unsigned long length)
  165. {
  166. return sys_truncate(path, length);
  167. }
  168. asmlinkage long sys_ftruncate64(unsigned int fd, unsigned long length)
  169. {
  170. return sys_ftruncate(fd, length);
  171. }
  172. asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long arg)
  173. {
  174. return sys_fcntl(fd, cmd, arg);
  175. }
  176. #else
  177. asmlinkage long parisc_truncate64(const char __user * path,
  178. unsigned int high, unsigned int low)
  179. {
  180. return sys_truncate64(path, (loff_t)high << 32 | low);
  181. }
  182. asmlinkage long parisc_ftruncate64(unsigned int fd,
  183. unsigned int high, unsigned int low)
  184. {
  185. return sys_ftruncate64(fd, (loff_t)high << 32 | low);
  186. }
  187. #endif
  188. asmlinkage ssize_t parisc_pread64(unsigned int fd, char __user *buf, size_t count,
  189. unsigned int high, unsigned int low)
  190. {
  191. return sys_pread64(fd, buf, count, (loff_t)high << 32 | low);
  192. }
  193. asmlinkage ssize_t parisc_pwrite64(unsigned int fd, const char __user *buf,
  194. size_t count, unsigned int high, unsigned int low)
  195. {
  196. return sys_pwrite64(fd, buf, count, (loff_t)high << 32 | low);
  197. }
  198. asmlinkage ssize_t parisc_readahead(int fd, unsigned int high, unsigned int low,
  199. size_t count)
  200. {
  201. return sys_readahead(fd, (loff_t)high << 32 | low, count);
  202. }
  203. asmlinkage long parisc_fadvise64_64(int fd,
  204. unsigned int high_off, unsigned int low_off,
  205. unsigned int high_len, unsigned int low_len, int advice)
  206. {
  207. return sys_fadvise64_64(fd, (loff_t)high_off << 32 | low_off,
  208. (loff_t)high_len << 32 | low_len, advice);
  209. }
  210. asmlinkage long parisc_sync_file_range(int fd,
  211. u32 hi_off, u32 lo_off, u32 hi_nbytes, u32 lo_nbytes,
  212. unsigned int flags)
  213. {
  214. return sys_sync_file_range(fd, (loff_t)hi_off << 32 | lo_off,
  215. (loff_t)hi_nbytes << 32 | lo_nbytes, flags);
  216. }
  217. asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr, unsigned long len, int prot, int flag)
  218. {
  219. return -ENOMEM;
  220. }
  221. asmlinkage int sys_free_hugepages(unsigned long addr)
  222. {
  223. return -EINVAL;
  224. }
  225. long parisc_personality(unsigned long personality)
  226. {
  227. long err;
  228. if (personality(current->personality) == PER_LINUX32
  229. && personality == PER_LINUX)
  230. personality = PER_LINUX32;
  231. err = sys_personality(personality);
  232. if (err == PER_LINUX32)
  233. err = PER_LINUX;
  234. return err;
  235. }
  236. long parisc_newuname(struct new_utsname __user *name)
  237. {
  238. int err = sys_newuname(name);
  239. #ifdef CONFIG_COMPAT
  240. if (!err && personality(current->personality) == PER_LINUX32) {
  241. if (__put_user(0, name->machine + 6) ||
  242. __put_user(0, name->machine + 7))
  243. err = -EFAULT;
  244. }
  245. #endif
  246. return err;
  247. }