sys_s390.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. #include <linux/personality.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/ipc.h>
  31. /*
  32. * sys_pipe() is the normal C calling standard for creating
  33. * a pipe. It's not the way Unix traditionally does this, though.
  34. */
  35. asmlinkage long sys_pipe(unsigned long __user *fildes)
  36. {
  37. int fd[2];
  38. int error;
  39. error = do_pipe(fd);
  40. if (!error) {
  41. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  42. error = -EFAULT;
  43. }
  44. return error;
  45. }
  46. /* common code for old and new mmaps */
  47. static inline long do_mmap2(
  48. unsigned long addr, unsigned long len,
  49. unsigned long prot, unsigned long flags,
  50. unsigned long fd, unsigned long pgoff)
  51. {
  52. long 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. /*
  69. * Perform the select(nd, in, out, ex, tv) and mmap() system
  70. * calls. Linux for S/390 isn't able to handle more than 5
  71. * system call parameters, so these system calls used a memory
  72. * block for parameter passing..
  73. */
  74. struct mmap_arg_struct {
  75. unsigned long addr;
  76. unsigned long len;
  77. unsigned long prot;
  78. unsigned long flags;
  79. unsigned long fd;
  80. unsigned long offset;
  81. };
  82. asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
  83. {
  84. struct mmap_arg_struct a;
  85. int error = -EFAULT;
  86. if (copy_from_user(&a, arg, sizeof(a)))
  87. goto out;
  88. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  89. out:
  90. return error;
  91. }
  92. asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
  93. {
  94. struct mmap_arg_struct a;
  95. long error = -EFAULT;
  96. if (copy_from_user(&a, arg, sizeof(a)))
  97. goto out;
  98. error = -EINVAL;
  99. if (a.offset & ~PAGE_MASK)
  100. goto out;
  101. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  102. out:
  103. return error;
  104. }
  105. #ifndef CONFIG_64BIT
  106. struct sel_arg_struct {
  107. unsigned long n;
  108. fd_set __user *inp, *outp, *exp;
  109. struct timeval __user *tvp;
  110. };
  111. asmlinkage long old_select(struct sel_arg_struct __user *arg)
  112. {
  113. struct sel_arg_struct a;
  114. if (copy_from_user(&a, arg, sizeof(a)))
  115. return -EFAULT;
  116. /* sys_select() does the appropriate kernel locking */
  117. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  118. }
  119. #endif /* CONFIG_64BIT */
  120. /*
  121. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  122. *
  123. * This is really horribly ugly.
  124. */
  125. asmlinkage long sys_ipc(uint call, int first, unsigned long second,
  126. unsigned long third, void __user *ptr)
  127. {
  128. struct ipc_kludge tmp;
  129. int ret;
  130. switch (call) {
  131. case SEMOP:
  132. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  133. (unsigned)second, NULL);
  134. case SEMTIMEDOP:
  135. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  136. (unsigned)second,
  137. (const struct timespec __user *) third);
  138. case SEMGET:
  139. return sys_semget(first, (int)second, third);
  140. case SEMCTL: {
  141. union semun fourth;
  142. if (!ptr)
  143. return -EINVAL;
  144. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  145. return -EFAULT;
  146. return sys_semctl(first, (int)second, third, fourth);
  147. }
  148. case MSGSND:
  149. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  150. (size_t)second, third);
  151. break;
  152. case MSGRCV:
  153. if (!ptr)
  154. return -EINVAL;
  155. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  156. sizeof (struct ipc_kludge)))
  157. return -EFAULT;
  158. return sys_msgrcv (first, tmp.msgp,
  159. (size_t)second, tmp.msgtyp, third);
  160. case MSGGET:
  161. return sys_msgget((key_t)first, (int)second);
  162. case MSGCTL:
  163. return sys_msgctl(first, (int)second,
  164. (struct msqid_ds __user *)ptr);
  165. case SHMAT: {
  166. ulong raddr;
  167. ret = do_shmat(first, (char __user *)ptr,
  168. (int)second, &raddr);
  169. if (ret)
  170. return ret;
  171. return put_user (raddr, (ulong __user *) third);
  172. break;
  173. }
  174. case SHMDT:
  175. return sys_shmdt ((char __user *)ptr);
  176. case SHMGET:
  177. return sys_shmget(first, (size_t)second, third);
  178. case SHMCTL:
  179. return sys_shmctl(first, (int)second,
  180. (struct shmid_ds __user *) ptr);
  181. default:
  182. return -ENOSYS;
  183. }
  184. return -EINVAL;
  185. }
  186. #ifdef CONFIG_64BIT
  187. asmlinkage long s390x_newuname(struct new_utsname __user *name)
  188. {
  189. int ret = sys_newuname(name);
  190. if (current->personality == PER_LINUX32 && !ret) {
  191. ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
  192. if (ret) ret = -EFAULT;
  193. }
  194. return ret;
  195. }
  196. asmlinkage long s390x_personality(unsigned long personality)
  197. {
  198. int ret;
  199. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  200. personality = PER_LINUX32;
  201. ret = sys_personality(personality);
  202. if (ret == PER_LINUX32)
  203. ret = PER_LINUX;
  204. return ret;
  205. }
  206. #endif /* CONFIG_64BIT */
  207. /*
  208. * Wrapper function for sys_fadvise64/fadvise64_64
  209. */
  210. #ifndef CONFIG_64BIT
  211. asmlinkage long
  212. s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
  213. {
  214. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  215. len, advice);
  216. }
  217. #endif
  218. struct fadvise64_64_args {
  219. int fd;
  220. long long offset;
  221. long long len;
  222. int advice;
  223. };
  224. asmlinkage long
  225. s390_fadvise64_64(struct fadvise64_64_args __user *args)
  226. {
  227. struct fadvise64_64_args a;
  228. if ( copy_from_user(&a, args, sizeof(a)) )
  229. return -EFAULT;
  230. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  231. }