sys_frv.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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/smp.h>
  16. #include <linux/sem.h>
  17. #include <linux/msg.h>
  18. #include <linux/shm.h>
  19. #include <linux/stat.h>
  20. #include <linux/mman.h>
  21. #include <linux/file.h>
  22. #include <linux/utsname.h>
  23. #include <linux/syscalls.h>
  24. #include <asm/setup.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/ipc.h>
  27. /*
  28. * sys_pipe() is the normal C calling standard for creating
  29. * a pipe. It's not the way unix traditionally does this, though.
  30. */
  31. asmlinkage long sys_pipe(unsigned long __user * fildes)
  32. {
  33. int fd[2];
  34. int error;
  35. error = do_pipe(fd);
  36. if (!error) {
  37. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  38. error = -EFAULT;
  39. }
  40. return error;
  41. }
  42. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  43. unsigned long prot, unsigned long flags,
  44. unsigned long fd, unsigned long pgoff)
  45. {
  46. int error = -EBADF;
  47. struct file * file = NULL;
  48. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  49. if (!(flags & MAP_ANONYMOUS)) {
  50. file = fget(fd);
  51. if (!file)
  52. goto out;
  53. }
  54. /* As with sparc32, make sure the shift for mmap2 is constant
  55. (12), no matter what PAGE_SIZE we have.... */
  56. /* But unlike sparc32, don't just silently break if we're
  57. trying to map something we can't */
  58. if (pgoff & ((1<<(PAGE_SHIFT-12))-1))
  59. return -EINVAL;
  60. pgoff >>= (PAGE_SHIFT - 12);
  61. down_write(&current->mm->mmap_sem);
  62. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  63. up_write(&current->mm->mmap_sem);
  64. if (file)
  65. fput(file);
  66. out:
  67. return error;
  68. }
  69. #if 0 /* DAVIDM - do we want this */
  70. struct mmap_arg_struct64 {
  71. __u32 addr;
  72. __u32 len;
  73. __u32 prot;
  74. __u32 flags;
  75. __u64 offset; /* 64 bits */
  76. __u32 fd;
  77. };
  78. asmlinkage long sys_mmap64(struct mmap_arg_struct64 *arg)
  79. {
  80. int error = -EFAULT;
  81. struct file * file = NULL;
  82. struct mmap_arg_struct64 a;
  83. unsigned long pgoff;
  84. if (copy_from_user(&a, arg, sizeof(a)))
  85. return -EFAULT;
  86. if ((long)a.offset & ~PAGE_MASK)
  87. return -EINVAL;
  88. pgoff = a.offset >> PAGE_SHIFT;
  89. if ((a.offset >> PAGE_SHIFT) != pgoff)
  90. return -EINVAL;
  91. if (!(a.flags & MAP_ANONYMOUS)) {
  92. error = -EBADF;
  93. file = fget(a.fd);
  94. if (!file)
  95. goto out;
  96. }
  97. a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  98. down_write(&current->mm->mmap_sem);
  99. error = do_mmap_pgoff(file, a.addr, a.len, a.prot, a.flags, pgoff);
  100. up_write(&current->mm->mmap_sem);
  101. if (file)
  102. fput(file);
  103. out:
  104. return error;
  105. }
  106. #endif
  107. /*
  108. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  109. *
  110. * This is really horribly ugly.
  111. */
  112. asmlinkage long sys_ipc(unsigned long call,
  113. unsigned long first,
  114. unsigned long second,
  115. unsigned long third,
  116. void __user *ptr,
  117. unsigned long fifth)
  118. {
  119. int version, ret;
  120. version = call >> 16; /* hack for backward compatibility */
  121. call &= 0xffff;
  122. switch (call) {
  123. case SEMOP:
  124. return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
  125. case SEMTIMEDOP:
  126. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  127. (const struct timespec __user *)fifth);
  128. case SEMGET:
  129. return sys_semget (first, second, third);
  130. case SEMCTL: {
  131. union semun fourth;
  132. if (!ptr)
  133. return -EINVAL;
  134. if (get_user(fourth.__pad, (void * __user *) ptr))
  135. return -EFAULT;
  136. return sys_semctl (first, second, third, fourth);
  137. }
  138. case MSGSND:
  139. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  140. second, third);
  141. case MSGRCV:
  142. switch (version) {
  143. case 0: {
  144. struct ipc_kludge tmp;
  145. if (!ptr)
  146. return -EINVAL;
  147. if (copy_from_user(&tmp,
  148. (struct ipc_kludge __user *) ptr,
  149. sizeof (tmp)))
  150. return -EFAULT;
  151. return sys_msgrcv (first, tmp.msgp, second,
  152. tmp.msgtyp, third);
  153. }
  154. default:
  155. return sys_msgrcv (first,
  156. (struct msgbuf __user *) ptr,
  157. second, fifth, third);
  158. }
  159. case MSGGET:
  160. return sys_msgget ((key_t) first, second);
  161. case MSGCTL:
  162. return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  163. case SHMAT:
  164. switch (version) {
  165. default: {
  166. ulong raddr;
  167. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  168. if (ret)
  169. return ret;
  170. return put_user (raddr, (ulong __user *) third);
  171. }
  172. case 1: /* iBCS2 emulator entry point */
  173. if (!segment_eq(get_fs(), get_ds()))
  174. return -EINVAL;
  175. /* The "(ulong *) third" is valid _only_ because of the kernel segment thing */
  176. return do_shmat (first, (char __user *) ptr, second, (ulong *) third);
  177. }
  178. case SHMDT:
  179. return sys_shmdt ((char __user *)ptr);
  180. case SHMGET:
  181. return sys_shmget (first, second, third);
  182. case SHMCTL:
  183. return sys_shmctl (first, second,
  184. (struct shmid_ds __user *) ptr);
  185. default:
  186. return -ENOSYS;
  187. }
  188. }