sys_frv.c 4.7 KB

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