sys_m32r.c 4.7 KB

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