sys_frv.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* sys_frv.c: FRV arch-specific syscall wrappers
  2. *
  3. * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. * - Derived from arch/m68k/kernel/sys_m68k.c
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/fs.h>
  16. #include <linux/smp.h>
  17. #include <linux/sem.h>
  18. #include <linux/msg.h>
  19. #include <linux/shm.h>
  20. #include <linux/stat.h>
  21. #include <linux/mman.h>
  22. #include <linux/file.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/ipc.h>
  25. #include <asm/setup.h>
  26. #include <asm/uaccess.h>
  27. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  28. unsigned long prot, unsigned long flags,
  29. unsigned long fd, unsigned long pgoff)
  30. {
  31. int error = -EBADF;
  32. struct file * file = NULL;
  33. /* As with sparc32, make sure the shift for mmap2 is constant
  34. (12), no matter what PAGE_SIZE we have.... */
  35. /* But unlike sparc32, don't just silently break if we're
  36. trying to map something we can't */
  37. if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
  38. return -EINVAL;
  39. pgoff >>= PAGE_SHIFT - 12;
  40. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  41. if (!(flags & MAP_ANONYMOUS)) {
  42. file = fget(fd);
  43. if (!file)
  44. goto out;
  45. }
  46. down_write(&current->mm->mmap_sem);
  47. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  48. up_write(&current->mm->mmap_sem);
  49. if (file)
  50. fput(file);
  51. out:
  52. return error;
  53. }
  54. #if 0 /* DAVIDM - do we want this */
  55. struct mmap_arg_struct64 {
  56. __u32 addr;
  57. __u32 len;
  58. __u32 prot;
  59. __u32 flags;
  60. __u64 offset; /* 64 bits */
  61. __u32 fd;
  62. };
  63. asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
  64. {
  65. int error = -EFAULT;
  66. struct file * file = NULL;
  67. struct mmap_arg_struct64 a;
  68. unsigned long pgoff;
  69. if (copy_from_user(&a, arg, sizeof(a)))
  70. return -EFAULT;
  71. if ((long)a.offset & ~PAGE_MASK)
  72. return -EINVAL;
  73. pgoff = a.offset >> PAGE_SHIFT;
  74. if ((a.offset >> PAGE_SHIFT) != pgoff)
  75. return -EINVAL;
  76. if (!(a.flags & MAP_ANONYMOUS)) {
  77. error = -EBADF;
  78. file = fget(a.fd);
  79. if (!file)
  80. goto out;
  81. }
  82. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  83. down_write(&current->mm->mmap_sem);
  84. error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
  85. up_write(&current->mm->mmap_sem);
  86. if (file)
  87. fput(file);
  88. out:
  89. return error;
  90. }
  91. #endif
  92. /*
  93. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  94. *
  95. * This is really horribly ugly.
  96. */
  97. asmlinkage long sys_ipc(unsigned long call,
  98. unsigned long first,
  99. unsigned long second,
  100. unsigned long third,
  101. void __user *ptr,
  102. unsigned long fifth)
  103. {
  104. int version, ret;
  105. version = call >> 16; /* hack for backward compatibility */
  106. call &= 0xffff;
  107. switch (call) {
  108. case SEMOP:
  109. return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
  110. case SEMTIMEDOP:
  111. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  112. (const struct timespec __user *)fifth);
  113. case SEMGET:
  114. return sys_semget (first, second, third);
  115. case SEMCTL: {
  116. union semun fourth;
  117. if (!ptr)
  118. return -EINVAL;
  119. if (get_user(fourth.__pad, (void * __user *) ptr))
  120. return -EFAULT;
  121. return sys_semctl (first, second, third, fourth);
  122. }
  123. case MSGSND:
  124. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  125. second, third);
  126. case MSGRCV:
  127. switch (version) {
  128. case 0: {
  129. struct ipc_kludge tmp;
  130. if (!ptr)
  131. return -EINVAL;
  132. if (copy_from_user(&tmp,
  133. (struct ipc_kludge __user *) ptr,
  134. sizeof (tmp)))
  135. return -EFAULT;
  136. return sys_msgrcv (first, tmp.msgp, second,
  137. tmp.msgtyp, third);
  138. }
  139. default:
  140. return sys_msgrcv (first,
  141. (struct msgbuf __user *) ptr,
  142. second, fifth, third);
  143. }
  144. case MSGGET:
  145. return sys_msgget ((key_t) first, second);
  146. case MSGCTL:
  147. return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  148. case SHMAT:
  149. switch (version) {
  150. default: {
  151. ulong raddr;
  152. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  153. if (ret)
  154. return ret;
  155. return put_user (raddr, (ulong __user *) third);
  156. }
  157. case 1: /* iBCS2 emulator entry point */
  158. if (!segment_eq(get_fs(), get_ds()))
  159. return -EINVAL;
  160. /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
  161. return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
  162. }
  163. case SHMDT:
  164. return sys_shmdt ((char __user *)ptr);
  165. case SHMGET:
  166. return sys_shmget (first, second, third);
  167. case SHMCTL:
  168. return sys_shmctl (first, second,
  169. (struct shmid_ds __user *) ptr);
  170. default:
  171. return -ENOSYS;
  172. }
  173. }