sys_frv.c 5.0 KB

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