sys_mn10300.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * memory mapping syscall
  30. */
  31. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  32. unsigned long prot, unsigned long flags,
  33. unsigned long fd, unsigned long pgoff)
  34. {
  35. struct file *file = NULL;
  36. long error = -EINVAL;
  37. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  38. if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
  39. goto out;
  40. error = -EBADF;
  41. if (!(flags & MAP_ANONYMOUS)) {
  42. file = fget(fd);
  43. if (!file)
  44. goto out;
  45. }
  46. down_write(&current->mm->mmap_sem);
  47. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  48. up_write(&current->mm->mmap_sem);
  49. if (file)
  50. fput(file);
  51. out:
  52. return error;
  53. }
  54. asmlinkage long old_mmap(unsigned long addr, unsigned long len,
  55. unsigned long prot, unsigned long flags,
  56. unsigned long fd, unsigned long offset)
  57. {
  58. if (offset & ~PAGE_MASK)
  59. return -EINVAL;
  60. return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  61. }
  62. struct sel_arg_struct {
  63. unsigned long n;
  64. fd_set *inp;
  65. fd_set *outp;
  66. fd_set *exp;
  67. struct timeval *tvp;
  68. };
  69. asmlinkage int old_select(struct sel_arg_struct __user *arg)
  70. {
  71. struct sel_arg_struct a;
  72. if (copy_from_user(&a, arg, sizeof(a)))
  73. return -EFAULT;
  74. /* sys_select() does the appropriate kernel locking */
  75. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  76. }
  77. /*
  78. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  79. *
  80. * This is really horribly ugly.
  81. */
  82. asmlinkage long sys_ipc(uint call, int first, int second,
  83. int third, void __user *ptr, long fifth)
  84. {
  85. int version, ret;
  86. version = call >> 16; /* hack for backward compatibility */
  87. call &= 0xffff;
  88. switch (call) {
  89. case SEMOP:
  90. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  91. second, NULL);
  92. case SEMTIMEDOP:
  93. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  94. second,
  95. (const struct timespec __user *)fifth);
  96. case SEMGET:
  97. return sys_semget(first, second, third);
  98. case SEMCTL: {
  99. union semun fourth;
  100. if (!ptr)
  101. return -EINVAL;
  102. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  103. return -EFAULT;
  104. return sys_semctl(first, second, third, fourth);
  105. }
  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. 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. case SHMAT:
  133. switch (version) {
  134. default: {
  135. ulong raddr;
  136. ret = do_shmat(first, (char __user *) ptr, second,
  137. &raddr);
  138. if (ret)
  139. return ret;
  140. return put_user(raddr, (ulong *) third);
  141. }
  142. case 1: /* iBCS2 emulator entry point */
  143. if (!segment_eq(get_fs(), get_ds()))
  144. return -EINVAL;
  145. return do_shmat(first, (char __user *) ptr, second,
  146. (ulong *) third);
  147. }
  148. case SHMDT:
  149. return sys_shmdt((char __user *)ptr);
  150. case SHMGET:
  151. return sys_shmget(first, second, third);
  152. case SHMCTL:
  153. return sys_shmctl(first, second,
  154. (struct shmid_ds __user *) ptr);
  155. default:
  156. return -EINVAL;
  157. }
  158. }