sys_cris.c 4.4 KB

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