sys_mn10300.c 4.1 KB

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