sys_mn10300.c 4.1 KB

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