sys_s390.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * arch/s390/kernel/sys_s390.c
  3. *
  4. * S390 version
  5. * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  7. * Thomas Spatzier (tspat@de.ibm.com)
  8. *
  9. * Derived from "arch/i386/kernel/sys_i386.c"
  10. *
  11. * This file contains various random system calls that
  12. * have a non-standard calling sequence on the Linux/s390
  13. * platform.
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/sched.h>
  17. #include <linux/mm.h>
  18. #include <linux/smp.h>
  19. #include <linux/smp_lock.h>
  20. #include <linux/sem.h>
  21. #include <linux/msg.h>
  22. #include <linux/shm.h>
  23. #include <linux/stat.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/mman.h>
  26. #include <linux/file.h>
  27. #include <linux/utsname.h>
  28. #ifdef CONFIG_ARCH_S390X
  29. #include <linux/personality.h>
  30. #endif /* CONFIG_ARCH_S390X */
  31. #include <asm/uaccess.h>
  32. #include <asm/ipc.h>
  33. /*
  34. * sys_pipe() is the normal C calling standard for creating
  35. * a pipe. It's not the way Unix traditionally does this, though.
  36. */
  37. asmlinkage long sys_pipe(unsigned long __user *fildes)
  38. {
  39. int fd[2];
  40. int error;
  41. error = do_pipe(fd);
  42. if (!error) {
  43. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  44. error = -EFAULT;
  45. }
  46. return error;
  47. }
  48. /* common code for old and new mmaps */
  49. static inline long do_mmap2(
  50. unsigned long addr, unsigned long len,
  51. unsigned long prot, unsigned long flags,
  52. unsigned long fd, unsigned long pgoff)
  53. {
  54. long error = -EBADF;
  55. struct file * file = NULL;
  56. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  57. if (!(flags & MAP_ANONYMOUS)) {
  58. file = fget(fd);
  59. if (!file)
  60. goto out;
  61. }
  62. down_write(&current->mm->mmap_sem);
  63. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  64. up_write(&current->mm->mmap_sem);
  65. if (file)
  66. fput(file);
  67. out:
  68. return error;
  69. }
  70. /*
  71. * Perform the select(nd, in, out, ex, tv) and mmap() system
  72. * calls. Linux for S/390 isn't able to handle more than 5
  73. * system call parameters, so these system calls used a memory
  74. * block for parameter passing..
  75. */
  76. struct mmap_arg_struct {
  77. unsigned long addr;
  78. unsigned long len;
  79. unsigned long prot;
  80. unsigned long flags;
  81. unsigned long fd;
  82. unsigned long offset;
  83. };
  84. asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
  85. {
  86. struct mmap_arg_struct a;
  87. int error = -EFAULT;
  88. if (copy_from_user(&a, arg, sizeof(a)))
  89. goto out;
  90. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  91. out:
  92. return error;
  93. }
  94. asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
  95. {
  96. struct mmap_arg_struct a;
  97. long error = -EFAULT;
  98. if (copy_from_user(&a, arg, sizeof(a)))
  99. goto out;
  100. error = -EINVAL;
  101. if (a.offset & ~PAGE_MASK)
  102. goto out;
  103. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  104. out:
  105. return error;
  106. }
  107. #ifndef CONFIG_ARCH_S390X
  108. struct sel_arg_struct {
  109. unsigned long n;
  110. fd_set *inp, *outp, *exp;
  111. struct timeval *tvp;
  112. };
  113. asmlinkage long old_select(struct sel_arg_struct __user *arg)
  114. {
  115. struct sel_arg_struct a;
  116. if (copy_from_user(&a, arg, sizeof(a)))
  117. return -EFAULT;
  118. /* sys_select() does the appropriate kernel locking */
  119. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  120. }
  121. #endif /* CONFIG_ARCH_S390X */
  122. /*
  123. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  124. *
  125. * This is really horribly ugly.
  126. */
  127. asmlinkage long sys_ipc(uint call, int first, unsigned long second,
  128. unsigned long third, void __user *ptr)
  129. {
  130. struct ipc_kludge tmp;
  131. int ret;
  132. switch (call) {
  133. case SEMOP:
  134. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  135. (unsigned)second, NULL);
  136. case SEMTIMEDOP:
  137. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  138. (unsigned)second,
  139. (const struct timespec __user *) third);
  140. case SEMGET:
  141. return sys_semget(first, (int)second, third);
  142. case SEMCTL: {
  143. union semun fourth;
  144. if (!ptr)
  145. return -EINVAL;
  146. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  147. return -EFAULT;
  148. return sys_semctl(first, (int)second, third, fourth);
  149. }
  150. case MSGSND:
  151. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  152. (size_t)second, third);
  153. break;
  154. case MSGRCV:
  155. if (!ptr)
  156. return -EINVAL;
  157. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  158. sizeof (struct ipc_kludge)))
  159. return -EFAULT;
  160. return sys_msgrcv (first, tmp.msgp,
  161. (size_t)second, tmp.msgtyp, third);
  162. case MSGGET:
  163. return sys_msgget((key_t)first, (int)second);
  164. case MSGCTL:
  165. return sys_msgctl(first, (int)second,
  166. (struct msqid_ds __user *)ptr);
  167. case SHMAT: {
  168. ulong raddr;
  169. ret = do_shmat(first, (char __user *)ptr,
  170. (int)second, &raddr);
  171. if (ret)
  172. return ret;
  173. return put_user (raddr, (ulong __user *) third);
  174. break;
  175. }
  176. case SHMDT:
  177. return sys_shmdt ((char __user *)ptr);
  178. case SHMGET:
  179. return sys_shmget(first, (size_t)second, third);
  180. case SHMCTL:
  181. return sys_shmctl(first, (int)second,
  182. (struct shmid_ds __user *) ptr);
  183. default:
  184. return -ENOSYS;
  185. }
  186. return -EINVAL;
  187. }
  188. #ifdef CONFIG_ARCH_S390X
  189. asmlinkage long s390x_newuname(struct new_utsname __user *name)
  190. {
  191. int ret = sys_newuname(name);
  192. if (current->personality == PER_LINUX32 && !ret) {
  193. ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
  194. if (ret) ret = -EFAULT;
  195. }
  196. return ret;
  197. }
  198. asmlinkage long s390x_personality(unsigned long personality)
  199. {
  200. int ret;
  201. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  202. personality = PER_LINUX32;
  203. ret = sys_personality(personality);
  204. if (ret == PER_LINUX32)
  205. ret = PER_LINUX;
  206. return ret;
  207. }
  208. #endif /* CONFIG_ARCH_S390X */
  209. /*
  210. * Wrapper function for sys_fadvise64/fadvise64_64
  211. */
  212. #ifndef CONFIG_ARCH_S390X
  213. asmlinkage long
  214. s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
  215. {
  216. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  217. len, advice);
  218. }
  219. #endif
  220. struct fadvise64_64_args {
  221. int fd;
  222. long long offset;
  223. long long len;
  224. int advice;
  225. };
  226. asmlinkage long
  227. s390_fadvise64_64(struct fadvise64_64_args __user *args)
  228. {
  229. struct fadvise64_64_args a;
  230. if ( copy_from_user(&a, args, sizeof(a)) )
  231. return -EFAULT;
  232. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  233. }