sys_sh.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * linux/arch/sh/kernel/sys_sh.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/SuperH
  6. * platform.
  7. *
  8. * Taken from i386 version.
  9. */
  10. #include <linux/errno.h>
  11. #include <linux/sched.h>
  12. #include <linux/mm.h>
  13. #include <linux/smp.h>
  14. #include <linux/sem.h>
  15. #include <linux/msg.h>
  16. #include <linux/shm.h>
  17. #include <linux/stat.h>
  18. #include <linux/syscalls.h>
  19. #include <linux/mman.h>
  20. #include <linux/file.h>
  21. #include <linux/utsname.h>
  22. #include <linux/module.h>
  23. #include <linux/fs.h>
  24. #include <linux/ipc.h>
  25. #include <asm/syscalls.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/unistd.h>
  28. static inline long
  29. do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  30. unsigned long flags, int fd, unsigned long pgoff)
  31. {
  32. int error = -EBADF;
  33. struct file *file = NULL;
  34. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  35. if (!(flags & MAP_ANONYMOUS)) {
  36. file = fget(fd);
  37. if (!file)
  38. goto out;
  39. }
  40. down_write(&current->mm->mmap_sem);
  41. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  42. up_write(&current->mm->mmap_sem);
  43. if (file)
  44. fput(file);
  45. out:
  46. return error;
  47. }
  48. asmlinkage int old_mmap(unsigned long addr, unsigned long len,
  49. unsigned long prot, unsigned long flags,
  50. int fd, unsigned long off)
  51. {
  52. if (off & ~PAGE_MASK)
  53. return -EINVAL;
  54. return do_mmap2(addr, len, prot, flags, fd, off>>PAGE_SHIFT);
  55. }
  56. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  57. unsigned long prot, unsigned long flags,
  58. unsigned long fd, unsigned long pgoff)
  59. {
  60. /*
  61. * The shift for mmap2 is constant, regardless of PAGE_SIZE
  62. * setting.
  63. */
  64. if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
  65. return -EINVAL;
  66. pgoff >>= PAGE_SHIFT - 12;
  67. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  68. }
  69. /*
  70. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  71. *
  72. * This is really horribly ugly.
  73. */
  74. asmlinkage int sys_ipc(uint call, int first, int second,
  75. int third, void __user *ptr, long fifth)
  76. {
  77. int version, ret;
  78. version = call >> 16; /* hack for backward compatibility */
  79. call &= 0xffff;
  80. trace_mark(kernel_arch_ipc_call, "call %u first %d", call, first);
  81. if (call <= SEMTIMEDOP)
  82. switch (call) {
  83. case SEMOP:
  84. return sys_semtimedop(first,
  85. (struct sembuf __user *)ptr,
  86. second, NULL);
  87. case SEMTIMEDOP:
  88. return sys_semtimedop(first,
  89. (struct sembuf __user *)ptr, second,
  90. (const struct timespec __user *)fifth);
  91. case SEMGET:
  92. return sys_semget (first, second, third);
  93. case SEMCTL: {
  94. union semun fourth;
  95. if (!ptr)
  96. return -EINVAL;
  97. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  98. return -EFAULT;
  99. return sys_semctl (first, second, third, fourth);
  100. }
  101. default:
  102. return -EINVAL;
  103. }
  104. if (call <= MSGCTL)
  105. switch (call) {
  106. case MSGSND:
  107. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  108. second, third);
  109. case MSGRCV:
  110. switch (version) {
  111. case 0:
  112. {
  113. struct ipc_kludge tmp;
  114. if (!ptr)
  115. return -EINVAL;
  116. if (copy_from_user(&tmp,
  117. (struct ipc_kludge __user *) ptr,
  118. sizeof (tmp)))
  119. return -EFAULT;
  120. return sys_msgrcv (first, tmp.msgp, second,
  121. tmp.msgtyp, third);
  122. }
  123. default:
  124. return sys_msgrcv (first,
  125. (struct msgbuf __user *) ptr,
  126. second, fifth, third);
  127. }
  128. case MSGGET:
  129. return sys_msgget ((key_t) first, second);
  130. case MSGCTL:
  131. return sys_msgctl (first, second,
  132. (struct msqid_ds __user *) ptr);
  133. default:
  134. return -EINVAL;
  135. }
  136. if (call <= SHMCTL)
  137. switch (call) {
  138. case SHMAT:
  139. switch (version) {
  140. default: {
  141. ulong raddr;
  142. ret = do_shmat (first, (char __user *) ptr,
  143. second, &raddr);
  144. if (ret)
  145. return ret;
  146. return put_user (raddr, (ulong __user *) third);
  147. }
  148. case 1: /* iBCS2 emulator entry point */
  149. if (!segment_eq(get_fs(), get_ds()))
  150. return -EINVAL;
  151. return do_shmat (first, (char __user *) ptr,
  152. second, (ulong *) third);
  153. }
  154. case SHMDT:
  155. return sys_shmdt ((char __user *)ptr);
  156. case SHMGET:
  157. return sys_shmget (first, second, third);
  158. case SHMCTL:
  159. return sys_shmctl (first, second,
  160. (struct shmid_ds __user *) ptr);
  161. default:
  162. return -EINVAL;
  163. }
  164. return -EINVAL;
  165. }
  166. asmlinkage int sys_uname(struct old_utsname __user *name)
  167. {
  168. int err;
  169. if (!name)
  170. return -EFAULT;
  171. down_read(&uts_sem);
  172. err = copy_to_user(name, utsname(), sizeof(*name));
  173. up_read(&uts_sem);
  174. return err?-EFAULT:0;
  175. }