sys_sh.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. if (call <= SEMTIMEDOP)
  81. switch (call) {
  82. case SEMOP:
  83. return sys_semtimedop(first,
  84. (struct sembuf __user *)ptr,
  85. second, NULL);
  86. case SEMTIMEDOP:
  87. return sys_semtimedop(first,
  88. (struct sembuf __user *)ptr, second,
  89. (const struct timespec __user *)fifth);
  90. case SEMGET:
  91. return sys_semget (first, second, third);
  92. case SEMCTL: {
  93. union semun fourth;
  94. if (!ptr)
  95. return -EINVAL;
  96. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  97. return -EFAULT;
  98. return sys_semctl (first, second, third, fourth);
  99. }
  100. default:
  101. return -EINVAL;
  102. }
  103. if (call <= MSGCTL)
  104. switch (call) {
  105. case MSGSND:
  106. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  107. second, third);
  108. case MSGRCV:
  109. switch (version) {
  110. case 0:
  111. {
  112. struct ipc_kludge tmp;
  113. if (!ptr)
  114. return -EINVAL;
  115. if (copy_from_user(&tmp,
  116. (struct ipc_kludge __user *) ptr,
  117. sizeof (tmp)))
  118. return -EFAULT;
  119. return sys_msgrcv (first, tmp.msgp, second,
  120. tmp.msgtyp, third);
  121. }
  122. default:
  123. return sys_msgrcv (first,
  124. (struct msgbuf __user *) ptr,
  125. second, fifth, third);
  126. }
  127. case MSGGET:
  128. return sys_msgget ((key_t) first, second);
  129. case MSGCTL:
  130. return sys_msgctl (first, second,
  131. (struct msqid_ds __user *) ptr);
  132. default:
  133. return -EINVAL;
  134. }
  135. if (call <= SHMCTL)
  136. switch (call) {
  137. case SHMAT:
  138. switch (version) {
  139. default: {
  140. ulong raddr;
  141. ret = do_shmat (first, (char __user *) ptr,
  142. second, &raddr);
  143. if (ret)
  144. return ret;
  145. return put_user (raddr, (ulong __user *) third);
  146. }
  147. case 1: /* iBCS2 emulator entry point */
  148. if (!segment_eq(get_fs(), get_ds()))
  149. return -EINVAL;
  150. return do_shmat (first, (char __user *) ptr,
  151. second, (ulong *) third);
  152. }
  153. case SHMDT:
  154. return sys_shmdt ((char __user *)ptr);
  155. case SHMGET:
  156. return sys_shmget (first, second, third);
  157. case SHMCTL:
  158. return sys_shmctl (first, second,
  159. (struct shmid_ds __user *) ptr);
  160. default:
  161. return -EINVAL;
  162. }
  163. return -EINVAL;
  164. }
  165. asmlinkage int sys_uname(struct old_utsname __user *name)
  166. {
  167. int err;
  168. if (!name)
  169. return -EFAULT;
  170. down_read(&uts_sem);
  171. err = copy_to_user(name, utsname(), sizeof(*name));
  172. up_read(&uts_sem);
  173. return err?-EFAULT:0;
  174. }