sys_cris.c 4.4 KB

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