sys_mn10300.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* MN10300 Weird system calls
  2. *
  3. * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
  4. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/sched.h>
  13. #include <linux/syscalls.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 <linux/tty.h>
  26. #include <asm/uaccess.h>
  27. #define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */
  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 __user *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. /*
  44. * memory mapping syscall
  45. */
  46. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  47. unsigned long prot, unsigned long flags,
  48. unsigned long fd, unsigned long pgoff)
  49. {
  50. struct file *file = NULL;
  51. long error = -EINVAL;
  52. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  53. if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
  54. goto out;
  55. error = -EBADF;
  56. if (!(flags & MAP_ANONYMOUS)) {
  57. file = fget(fd);
  58. if (!file)
  59. goto out;
  60. }
  61. down_write(&current->mm->mmap_sem);
  62. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  63. up_write(&current->mm->mmap_sem);
  64. if (file)
  65. fput(file);
  66. out:
  67. return error;
  68. }
  69. asmlinkage long old_mmap(unsigned long addr, unsigned long len,
  70. unsigned long prot, unsigned long flags,
  71. unsigned long fd, unsigned long offset)
  72. {
  73. if (offset & ~PAGE_MASK)
  74. return -EINVAL;
  75. return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  76. }
  77. struct sel_arg_struct {
  78. unsigned long n;
  79. fd_set *inp;
  80. fd_set *outp;
  81. fd_set *exp;
  82. struct timeval *tvp;
  83. };
  84. asmlinkage int old_select(struct sel_arg_struct __user *arg)
  85. {
  86. struct sel_arg_struct a;
  87. if (copy_from_user(&a, arg, sizeof(a)))
  88. return -EFAULT;
  89. /* sys_select() does the appropriate kernel locking */
  90. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  91. }
  92. /*
  93. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  94. *
  95. * This is really horribly ugly.
  96. */
  97. asmlinkage long sys_ipc(uint call, int first, int second,
  98. int third, void __user *ptr, long fifth)
  99. {
  100. int version, ret;
  101. version = call >> 16; /* hack for backward compatibility */
  102. call &= 0xffff;
  103. switch (call) {
  104. case SEMOP:
  105. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  106. second, NULL);
  107. case SEMTIMEDOP:
  108. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  109. second,
  110. (const struct timespec __user *)fifth);
  111. case SEMGET:
  112. return sys_semget(first, second, third);
  113. case SEMCTL: {
  114. union semun fourth;
  115. if (!ptr)
  116. return -EINVAL;
  117. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  118. return -EFAULT;
  119. return sys_semctl(first, second, third, fourth);
  120. }
  121. case MSGSND:
  122. return sys_msgsnd(first, (struct msgbuf __user *) ptr,
  123. second, third);
  124. case MSGRCV:
  125. switch (version) {
  126. case 0: {
  127. struct ipc_kludge tmp;
  128. if (!ptr)
  129. return -EINVAL;
  130. if (copy_from_user(&tmp,
  131. (struct ipc_kludge __user *) ptr,
  132. sizeof(tmp)))
  133. return -EFAULT;
  134. return sys_msgrcv(first, tmp.msgp, second,
  135. tmp.msgtyp, third);
  136. }
  137. default:
  138. return sys_msgrcv(first,
  139. (struct msgbuf __user *) ptr,
  140. second, fifth, third);
  141. }
  142. case MSGGET:
  143. return sys_msgget((key_t) first, second);
  144. case MSGCTL:
  145. return sys_msgctl(first, second,
  146. (struct msqid_ds __user *) ptr);
  147. case SHMAT:
  148. switch (version) {
  149. default: {
  150. ulong raddr;
  151. ret = do_shmat(first, (char __user *) ptr, second,
  152. &raddr);
  153. if (ret)
  154. return ret;
  155. return put_user(raddr, (ulong *) third);
  156. }
  157. case 1: /* iBCS2 emulator entry point */
  158. if (!segment_eq(get_fs(), get_ds()))
  159. return -EINVAL;
  160. return do_shmat(first, (char __user *) ptr, second,
  161. (ulong *) third);
  162. }
  163. case SHMDT:
  164. return sys_shmdt((char __user *)ptr);
  165. case SHMGET:
  166. return sys_shmget(first, second, third);
  167. case SHMCTL:
  168. return sys_shmctl(first, second,
  169. (struct shmid_ds __user *) ptr);
  170. default:
  171. return -EINVAL;
  172. }
  173. }