sys_m32r.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * linux/arch/m32r/kernel/sys_m32r.c
  3. *
  4. * This file contains various random system calls that
  5. * have a non-standard calling sequence on the Linux/M32R platform.
  6. *
  7. * Taken from i386 version.
  8. */
  9. #include <linux/config.h>
  10. #include <linux/errno.h>
  11. #include <linux/sched.h>
  12. #include <linux/mm.h>
  13. #include <linux/smp.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/sem.h>
  16. #include <linux/msg.h>
  17. #include <linux/shm.h>
  18. #include <linux/stat.h>
  19. #include <linux/syscalls.h>
  20. #include <linux/mman.h>
  21. #include <linux/file.h>
  22. #include <linux/utsname.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/cachectl.h>
  25. #include <asm/cacheflush.h>
  26. #include <asm/ipc.h>
  27. /*
  28. * sys_tas() - test-and-set
  29. * linuxthreads testing version
  30. */
  31. #ifndef CONFIG_SMP
  32. asmlinkage int sys_tas(int *addr)
  33. {
  34. int oldval;
  35. unsigned long flags;
  36. if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
  37. return -EFAULT;
  38. local_irq_save(flags);
  39. oldval = *addr;
  40. *addr = 1;
  41. local_irq_restore(flags);
  42. return oldval;
  43. }
  44. #else /* CONFIG_SMP */
  45. #include <linux/spinlock.h>
  46. static DEFINE_SPINLOCK(tas_lock);
  47. asmlinkage int sys_tas(int *addr)
  48. {
  49. int oldval;
  50. if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
  51. return -EFAULT;
  52. _raw_spin_lock(&tas_lock);
  53. oldval = *addr;
  54. *addr = 1;
  55. _raw_spin_unlock(&tas_lock);
  56. return oldval;
  57. }
  58. #endif /* CONFIG_SMP */
  59. /*
  60. * sys_pipe() is the normal C calling standard for creating
  61. * a pipe. It's not the way Unix traditionally does this, though.
  62. */
  63. asmlinkage int
  64. sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,
  65. unsigned long r3, unsigned long r4, unsigned long r5,
  66. unsigned long r6, struct pt_regs regs)
  67. {
  68. int fd[2];
  69. int error;
  70. error = do_pipe(fd);
  71. if (!error) {
  72. if (copy_to_user((void *)r0, (void *)fd, 2*sizeof(int)))
  73. error = -EFAULT;
  74. }
  75. return error;
  76. }
  77. asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
  78. unsigned long prot, unsigned long flags,
  79. unsigned long fd, unsigned long pgoff)
  80. {
  81. int error = -EBADF;
  82. struct file *file = NULL;
  83. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  84. if (!(flags & MAP_ANONYMOUS)) {
  85. file = fget(fd);
  86. if (!file)
  87. goto out;
  88. }
  89. down_write(&current->mm->mmap_sem);
  90. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  91. up_write(&current->mm->mmap_sem);
  92. if (file)
  93. fput(file);
  94. out:
  95. return error;
  96. }
  97. /*
  98. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  99. *
  100. * This is really horribly ugly.
  101. */
  102. asmlinkage int sys_ipc(uint call, int first, int second,
  103. int third, void __user *ptr, long fifth)
  104. {
  105. int version, ret;
  106. version = call >> 16; /* hack for backward compatibility */
  107. call &= 0xffff;
  108. switch (call) {
  109. case SEMOP:
  110. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  111. second, NULL);
  112. case SEMTIMEDOP:
  113. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  114. second, (const struct timespec __user *)fifth);
  115. case SEMGET:
  116. return sys_semget (first, second, third);
  117. case SEMCTL: {
  118. union semun fourth;
  119. if (!ptr)
  120. return -EINVAL;
  121. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  122. return -EFAULT;
  123. return sys_semctl (first, second, third, fourth);
  124. }
  125. case MSGSND:
  126. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  127. second, third);
  128. case MSGRCV:
  129. switch (version) {
  130. case 0: {
  131. struct ipc_kludge tmp;
  132. if (!ptr)
  133. return -EINVAL;
  134. if (copy_from_user(&tmp,
  135. (struct ipc_kludge __user *) ptr,
  136. sizeof (tmp)))
  137. return -EFAULT;
  138. return sys_msgrcv (first, tmp.msgp, second,
  139. tmp.msgtyp, third);
  140. }
  141. default:
  142. return sys_msgrcv (first,
  143. (struct msgbuf __user *) ptr,
  144. second, fifth, third);
  145. }
  146. case MSGGET:
  147. return sys_msgget ((key_t) first, second);
  148. case MSGCTL:
  149. return sys_msgctl (first, second,
  150. (struct msqid_ds __user *) ptr);
  151. case SHMAT: {
  152. ulong raddr;
  153. if (!access_ok(VERIFY_WRITE, (ulong __user *) third,
  154. sizeof(ulong)))
  155. return -EFAULT;
  156. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  157. if (ret)
  158. return ret;
  159. return put_user (raddr, (ulong __user *) third);
  160. }
  161. case SHMDT:
  162. return sys_shmdt ((char __user *)ptr);
  163. case SHMGET:
  164. return sys_shmget (first, second, third);
  165. case SHMCTL:
  166. return sys_shmctl (first, second,
  167. (struct shmid_ds __user *) ptr);
  168. default:
  169. return -ENOSYS;
  170. }
  171. }
  172. asmlinkage int sys_uname(struct old_utsname * name)
  173. {
  174. int err;
  175. if (!name)
  176. return -EFAULT;
  177. down_read(&uts_sem);
  178. err=copy_to_user(name, &system_utsname, sizeof (*name));
  179. up_read(&uts_sem);
  180. return err?-EFAULT:0;
  181. }
  182. asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
  183. {
  184. /* This should flush more selectivly ... */
  185. _flush_cache_all();
  186. return 0;
  187. }
  188. asmlinkage int sys_cachectl(char *addr, int nbytes, int op)
  189. {
  190. /* Not implemented yet. */
  191. return -ENOSYS;
  192. }