sys_mn10300.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/sem.h>
  17. #include <linux/msg.h>
  18. #include <linux/shm.h>
  19. #include <linux/stat.h>
  20. #include <linux/mman.h>
  21. #include <linux/file.h>
  22. #include <linux/utsname.h>
  23. #include <linux/syscalls.h>
  24. #include <linux/tty.h>
  25. #include <asm/uaccess.h>
  26. #define MIN_MAP_ADDR PAGE_SIZE /* minimum fixed mmap address */
  27. /*
  28. * memory mapping syscall
  29. */
  30. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  31. unsigned long prot, unsigned long flags,
  32. unsigned long fd, unsigned long pgoff)
  33. {
  34. struct file *file = NULL;
  35. long error = -EINVAL;
  36. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  37. if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
  38. goto out;
  39. error = -EBADF;
  40. if (!(flags & MAP_ANONYMOUS)) {
  41. file = fget(fd);
  42. if (!file)
  43. goto out;
  44. }
  45. down_write(&current->mm->mmap_sem);
  46. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  47. up_write(&current->mm->mmap_sem);
  48. if (file)
  49. fput(file);
  50. out:
  51. return error;
  52. }
  53. asmlinkage long old_mmap(unsigned long addr, unsigned long len,
  54. unsigned long prot, unsigned long flags,
  55. unsigned long fd, unsigned long offset)
  56. {
  57. if (offset & ~PAGE_MASK)
  58. return -EINVAL;
  59. return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  60. }
  61. struct sel_arg_struct {
  62. unsigned long n;
  63. fd_set *inp;
  64. fd_set *outp;
  65. fd_set *exp;
  66. struct timeval *tvp;
  67. };
  68. asmlinkage int old_select(struct sel_arg_struct __user *arg)
  69. {
  70. struct sel_arg_struct a;
  71. if (copy_from_user(&a, arg, sizeof(a)))
  72. return -EFAULT;
  73. /* sys_select() does the appropriate kernel locking */
  74. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  75. }
  76. /*
  77. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  78. *
  79. * This is really horribly ugly.
  80. */
  81. asmlinkage long sys_ipc(uint call, int first, int second,
  82. int third, void __user *ptr, long fifth)
  83. {
  84. int version, ret;
  85. version = call >> 16; /* hack for backward compatibility */
  86. call &= 0xffff;
  87. switch (call) {
  88. case SEMOP:
  89. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  90. second, NULL);
  91. case SEMTIMEDOP:
  92. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  93. second,
  94. (const struct timespec __user *)fifth);
  95. case SEMGET:
  96. return sys_semget(first, second, third);
  97. case SEMCTL: {
  98. union semun fourth;
  99. if (!ptr)
  100. return -EINVAL;
  101. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  102. return -EFAULT;
  103. return sys_semctl(first, second, third, fourth);
  104. }
  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. struct ipc_kludge tmp;
  112. if (!ptr)
  113. return -EINVAL;
  114. if (copy_from_user(&tmp,
  115. (struct ipc_kludge __user *) ptr,
  116. sizeof(tmp)))
  117. return -EFAULT;
  118. return sys_msgrcv(first, tmp.msgp, second,
  119. tmp.msgtyp, third);
  120. }
  121. default:
  122. return sys_msgrcv(first,
  123. (struct msgbuf __user *) ptr,
  124. second, fifth, third);
  125. }
  126. case MSGGET:
  127. return sys_msgget((key_t) first, second);
  128. case MSGCTL:
  129. return sys_msgctl(first, second,
  130. (struct msqid_ds __user *) ptr);
  131. case SHMAT:
  132. switch (version) {
  133. default: {
  134. ulong raddr;
  135. ret = do_shmat(first, (char __user *) ptr, second,
  136. &raddr);
  137. if (ret)
  138. return ret;
  139. return put_user(raddr, (ulong *) 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, second,
  145. (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. }