syscall.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * arch/xtensa/kernel/syscall.c
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. * Copyright (C) 2000 Silicon Graphics, Inc.
  10. * Copyright (C) 1995 - 2000 by Ralf Baechle
  11. *
  12. * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
  13. * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
  14. * Chris Zankel <chris@zankel.net>
  15. * Kevin Chea
  16. *
  17. */
  18. #include <linux/uaccess.h>
  19. #include <asm/syscall.h>
  20. #include <asm/unistd.h>
  21. #include <linux/linkage.h>
  22. #include <linux/stringify.h>
  23. #include <linux/errno.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/file.h>
  26. #include <linux/fs.h>
  27. #include <linux/mman.h>
  28. #include <linux/sched/mm.h>
  29. #include <linux/shm.h>
  30. syscall_t sys_call_table[__NR_syscalls] /* FIXME __cacheline_aligned */= {
  31. [0 ... __NR_syscalls - 1] = (syscall_t)&sys_ni_syscall,
  32. #define __SYSCALL(nr, entry, nargs)[nr] = (syscall_t)entry,
  33. #include <asm/syscall_table.h>
  34. #undef __SYSCALL
  35. };
  36. #define COLOUR_ALIGN(addr, pgoff) \
  37. ((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
  38. (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
  39. asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
  40. {
  41. unsigned long ret;
  42. long err;
  43. err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
  44. if (err)
  45. return err;
  46. return (long)ret;
  47. }
  48. asmlinkage long xtensa_fadvise64_64(int fd, int advice,
  49. unsigned long long offset, unsigned long long len)
  50. {
  51. return ksys_fadvise64_64(fd, offset, len, advice);
  52. }
  53. #ifdef CONFIG_MMU
  54. unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
  55. unsigned long len, unsigned long pgoff, unsigned long flags)
  56. {
  57. struct vm_area_struct *vmm;
  58. if (flags & MAP_FIXED) {
  59. /* We do not accept a shared mapping if it would violate
  60. * cache aliasing constraints.
  61. */
  62. if ((flags & MAP_SHARED) &&
  63. ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
  64. return -EINVAL;
  65. return addr;
  66. }
  67. if (len > TASK_SIZE)
  68. return -ENOMEM;
  69. if (!addr)
  70. addr = TASK_UNMAPPED_BASE;
  71. if (flags & MAP_SHARED)
  72. addr = COLOUR_ALIGN(addr, pgoff);
  73. else
  74. addr = PAGE_ALIGN(addr);
  75. for (vmm = find_vma(current->mm, addr); ; vmm = vmm->vm_next) {
  76. /* At this point: (!vmm || addr < vmm->vm_end). */
  77. if (TASK_SIZE - len < addr)
  78. return -ENOMEM;
  79. if (!vmm || addr + len <= vm_start_gap(vmm))
  80. return addr;
  81. addr = vmm->vm_end;
  82. if (flags & MAP_SHARED)
  83. addr = COLOUR_ALIGN(addr, pgoff);
  84. }
  85. }
  86. #endif