sys_cris.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* $Id: sys_cris.c,v 1.6 2004/03/11 11:38:40 starvik Exp $
  2. *
  3. * linux/arch/cris/kernel/sys_cris.c
  4. *
  5. * This file contains various random system calls that
  6. * have a non-standard calling sequence on some platforms.
  7. * Since we don't have to do any backwards compatibility, our
  8. * versions are done in the most "normal" way possible.
  9. *
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/sched.h>
  13. #include <linux/syscalls.h>
  14. #include <linux/mm.h>
  15. #include <linux/fs.h>
  16. #include <linux/smp.h>
  17. #include <linux/smp_lock.h>
  18. #include <linux/sem.h>
  19. #include <linux/msg.h>
  20. #include <linux/shm.h>
  21. #include <linux/stat.h>
  22. #include <linux/mman.h>
  23. #include <linux/file.h>
  24. #include <linux/ipc.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/segment.h>
  27. /*
  28. * sys_pipe() is the normal C calling standard for creating
  29. * a pipe. It's not the way Unix traditionally does this, though.
  30. */
  31. asmlinkage int sys_pipe(unsigned long __user * fildes)
  32. {
  33. int fd[2];
  34. int error;
  35. lock_kernel();
  36. error = do_pipe(fd);
  37. unlock_kernel();
  38. if (!error) {
  39. if (copy_to_user(fildes, fd, 2*sizeof(int))) {
  40. sys_close(fd[0]);
  41. sys_close(fd[1]);
  42. error = -EFAULT;
  43. }
  44. }
  45. return error;
  46. }
  47. /* common code for old and new mmaps */
  48. static inline long
  49. do_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  50. unsigned long flags, unsigned long fd, unsigned long pgoff)
  51. {
  52. int error = -EBADF;
  53. struct file * file = NULL;
  54. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  55. if (!(flags & MAP_ANONYMOUS)) {
  56. file = fget(fd);
  57. if (!file)
  58. goto out;
  59. }
  60. down_write(&current->mm->mmap_sem);
  61. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  62. up_write(&current->mm->mmap_sem);
  63. if (file)
  64. fput(file);
  65. out:
  66. return error;
  67. }
  68. asmlinkage unsigned long old_mmap(unsigned long __user *args)
  69. {
  70. unsigned long buffer[6];
  71. int err = -EFAULT;
  72. if (copy_from_user(&buffer, args, sizeof(buffer)))
  73. goto out;
  74. err = -EINVAL;
  75. if (buffer[5] & ~PAGE_MASK) /* verify that offset is on page boundary */
  76. goto out;
  77. err = do_mmap2(buffer[0], buffer[1], buffer[2], buffer[3],
  78. buffer[4], buffer[5] >> PAGE_SHIFT);
  79. out:
  80. return err;
  81. }
  82. asmlinkage long
  83. sys_mmap2(unsigned long addr, unsigned long len, unsigned long prot,
  84. unsigned long flags, unsigned long fd, unsigned long pgoff)
  85. {
  86. return do_mmap2(addr, len, prot, flags, fd, pgoff);
  87. }
  88. /*
  89. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  90. *
  91. * This is really horribly ugly. (same as arch/i386)
  92. */
  93. asmlinkage int sys_ipc (uint call, int first, int second,
  94. int third, void __user *ptr, long fifth)
  95. {
  96. int version, ret;
  97. version = call >> 16; /* hack for backward compatibility */
  98. call &= 0xffff;
  99. switch (call) {
  100. case SEMOP:
  101. return sys_semtimedop (first, (struct sembuf __user *)ptr, second, NULL);
  102. case SEMTIMEDOP:
  103. return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
  104. (const struct timespec __user *)fifth);
  105. case SEMGET:
  106. return sys_semget (first, second, third);
  107. case SEMCTL: {
  108. union semun fourth;
  109. if (!ptr)
  110. return -EINVAL;
  111. if (get_user(fourth.__pad, (void * __user *) ptr))
  112. return -EFAULT;
  113. return sys_semctl (first, second, third, fourth);
  114. }
  115. case MSGSND:
  116. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  117. second, third);
  118. case MSGRCV:
  119. switch (version) {
  120. case 0: {
  121. struct ipc_kludge tmp;
  122. if (!ptr)
  123. return -EINVAL;
  124. if (copy_from_user(&tmp,
  125. (struct ipc_kludge __user *) ptr,
  126. sizeof (tmp)))
  127. return -EFAULT;
  128. return sys_msgrcv (first, tmp.msgp, second,
  129. tmp.msgtyp, third);
  130. }
  131. default:
  132. return sys_msgrcv (first,
  133. (struct msgbuf __user *) ptr,
  134. second, fifth, third);
  135. }
  136. case MSGGET:
  137. return sys_msgget ((key_t) first, second);
  138. case MSGCTL:
  139. return sys_msgctl (first, second, (struct msqid_ds __user *) ptr);
  140. case SHMAT: {
  141. ulong raddr;
  142. ret = do_shmat (first, (char __user *) ptr, second, &raddr);
  143. if (ret)
  144. return ret;
  145. return put_user (raddr, (ulong __user *) 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 -ENOSYS;
  156. }
  157. }