sys_sh.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  61. }
  62. /*
  63. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  64. *
  65. * This is really horribly ugly.
  66. */
  67. asmlinkage int sys_ipc(uint call, int first, int second,
  68. int third, void __user *ptr, long fifth)
  69. {
  70. int version, ret;
  71. version = call >> 16; /* hack for backward compatibility */
  72. call &= 0xffff;
  73. trace_mark(kernel_arch_ipc_call, "call %u first %d", call, first);
  74. if (call <= SEMTIMEDOP)
  75. switch (call) {
  76. case SEMOP:
  77. return sys_semtimedop(first,
  78. (struct sembuf __user *)ptr,
  79. second, NULL);
  80. case SEMTIMEDOP:
  81. return sys_semtimedop(first,
  82. (struct sembuf __user *)ptr, second,
  83. (const struct timespec __user *)fifth);
  84. case SEMGET:
  85. return sys_semget (first, second, third);
  86. case SEMCTL: {
  87. union semun fourth;
  88. if (!ptr)
  89. return -EINVAL;
  90. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  91. return -EFAULT;
  92. return sys_semctl (first, second, third, fourth);
  93. }
  94. default:
  95. return -EINVAL;
  96. }
  97. if (call <= MSGCTL)
  98. switch (call) {
  99. case MSGSND:
  100. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  101. second, third);
  102. case MSGRCV:
  103. switch (version) {
  104. case 0:
  105. {
  106. struct ipc_kludge tmp;
  107. if (!ptr)
  108. return -EINVAL;
  109. if (copy_from_user(&tmp,
  110. (struct ipc_kludge __user *) ptr,
  111. sizeof (tmp)))
  112. return -EFAULT;
  113. return sys_msgrcv (first, tmp.msgp, second,
  114. tmp.msgtyp, third);
  115. }
  116. default:
  117. return sys_msgrcv (first,
  118. (struct msgbuf __user *) ptr,
  119. second, fifth, third);
  120. }
  121. case MSGGET:
  122. return sys_msgget ((key_t) first, second);
  123. case MSGCTL:
  124. return sys_msgctl (first, second,
  125. (struct msqid_ds __user *) ptr);
  126. default:
  127. return -EINVAL;
  128. }
  129. if (call <= SHMCTL)
  130. switch (call) {
  131. case SHMAT:
  132. switch (version) {
  133. default: {
  134. ulong raddr;
  135. ret = do_shmat (first, (char __user *) ptr,
  136. second, &raddr);
  137. if (ret)
  138. return ret;
  139. return put_user (raddr, (ulong __user *) third);
  140. }
  141. case 1: /* iBCS2 emulator entry point */
  142. if (!segment_eq(get_fs(), get_ds()))
  143. return -EINVAL;
  144. return do_shmat (first, (char __user *) ptr,
  145. second, (ulong *) third);
  146. }
  147. case SHMDT:
  148. return sys_shmdt ((char __user *)ptr);
  149. case SHMGET:
  150. return sys_shmget (first, second, third);
  151. case SHMCTL:
  152. return sys_shmctl (first, second,
  153. (struct shmid_ds __user *) ptr);
  154. default:
  155. return -EINVAL;
  156. }
  157. return -EINVAL;
  158. }
  159. asmlinkage int sys_uname(struct old_utsname __user *name)
  160. {
  161. int err;
  162. if (!name)
  163. return -EFAULT;
  164. down_read(&uts_sem);
  165. err = copy_to_user(name, utsname(), sizeof(*name));
  166. up_read(&uts_sem);
  167. return err?-EFAULT:0;
  168. }