sys_s390.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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/fs.h>
  19. #include <linux/smp.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 <linux/unistd.h>
  30. #include <linux/ipc.h>
  31. #include <asm/uaccess.h>
  32. /*
  33. * sys_pipe() is the normal C calling standard for creating
  34. * a pipe. It's not the way Unix traditionally does this, though.
  35. */
  36. asmlinkage long sys_pipe(unsigned long __user *fildes)
  37. {
  38. int fd[2];
  39. int error;
  40. error = do_pipe(fd);
  41. if (!error) {
  42. if (copy_to_user(fildes, fd, 2*sizeof(int)))
  43. error = -EFAULT;
  44. }
  45. return error;
  46. }
  47. /* common code for old and new mmaps */
  48. static inline long do_mmap2(
  49. unsigned long addr, unsigned long len,
  50. unsigned long prot, unsigned long flags,
  51. unsigned long fd, unsigned long pgoff)
  52. {
  53. long error = -EBADF;
  54. struct file * file = NULL;
  55. flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
  56. if (!(flags & MAP_ANONYMOUS)) {
  57. file = fget(fd);
  58. if (!file)
  59. goto out;
  60. }
  61. down_write(&current->mm->mmap_sem);
  62. error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
  63. up_write(&current->mm->mmap_sem);
  64. if (file)
  65. fput(file);
  66. out:
  67. return error;
  68. }
  69. /*
  70. * Perform the select(nd, in, out, ex, tv) and mmap() system
  71. * calls. Linux for S/390 isn't able to handle more than 5
  72. * system call parameters, so these system calls used a memory
  73. * block for parameter passing..
  74. */
  75. struct mmap_arg_struct {
  76. unsigned long addr;
  77. unsigned long len;
  78. unsigned long prot;
  79. unsigned long flags;
  80. unsigned long fd;
  81. unsigned long offset;
  82. };
  83. asmlinkage long sys_mmap2(struct mmap_arg_struct __user *arg)
  84. {
  85. struct mmap_arg_struct a;
  86. int error = -EFAULT;
  87. if (copy_from_user(&a, arg, sizeof(a)))
  88. goto out;
  89. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset);
  90. out:
  91. return error;
  92. }
  93. asmlinkage long old_mmap(struct mmap_arg_struct __user *arg)
  94. {
  95. struct mmap_arg_struct a;
  96. long error = -EFAULT;
  97. if (copy_from_user(&a, arg, sizeof(a)))
  98. goto out;
  99. error = -EINVAL;
  100. if (a.offset & ~PAGE_MASK)
  101. goto out;
  102. error = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT);
  103. out:
  104. return error;
  105. }
  106. #ifndef CONFIG_64BIT
  107. struct sel_arg_struct {
  108. unsigned long n;
  109. fd_set __user *inp, *outp, *exp;
  110. struct timeval __user *tvp;
  111. };
  112. asmlinkage long old_select(struct sel_arg_struct __user *arg)
  113. {
  114. struct sel_arg_struct a;
  115. if (copy_from_user(&a, arg, sizeof(a)))
  116. return -EFAULT;
  117. /* sys_select() does the appropriate kernel locking */
  118. return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
  119. }
  120. #endif /* CONFIG_64BIT */
  121. /*
  122. * sys_ipc() is the de-multiplexer for the SysV IPC calls..
  123. *
  124. * This is really horribly ugly.
  125. */
  126. asmlinkage long sys_ipc(uint call, int first, unsigned long second,
  127. unsigned long third, void __user *ptr)
  128. {
  129. struct ipc_kludge tmp;
  130. int ret;
  131. switch (call) {
  132. case SEMOP:
  133. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  134. (unsigned)second, NULL);
  135. case SEMTIMEDOP:
  136. return sys_semtimedop(first, (struct sembuf __user *)ptr,
  137. (unsigned)second,
  138. (const struct timespec __user *) third);
  139. case SEMGET:
  140. return sys_semget(first, (int)second, third);
  141. case SEMCTL: {
  142. union semun fourth;
  143. if (!ptr)
  144. return -EINVAL;
  145. if (get_user(fourth.__pad, (void __user * __user *) ptr))
  146. return -EFAULT;
  147. return sys_semctl(first, (int)second, third, fourth);
  148. }
  149. case MSGSND:
  150. return sys_msgsnd (first, (struct msgbuf __user *) ptr,
  151. (size_t)second, third);
  152. break;
  153. case MSGRCV:
  154. if (!ptr)
  155. return -EINVAL;
  156. if (copy_from_user (&tmp, (struct ipc_kludge __user *) ptr,
  157. sizeof (struct ipc_kludge)))
  158. return -EFAULT;
  159. return sys_msgrcv (first, tmp.msgp,
  160. (size_t)second, tmp.msgtyp, third);
  161. case MSGGET:
  162. return sys_msgget((key_t)first, (int)second);
  163. case MSGCTL:
  164. return sys_msgctl(first, (int)second,
  165. (struct msqid_ds __user *)ptr);
  166. case SHMAT: {
  167. ulong raddr;
  168. ret = do_shmat(first, (char __user *)ptr,
  169. (int)second, &raddr);
  170. if (ret)
  171. return ret;
  172. return put_user (raddr, (ulong __user *) third);
  173. break;
  174. }
  175. case SHMDT:
  176. return sys_shmdt ((char __user *)ptr);
  177. case SHMGET:
  178. return sys_shmget(first, (size_t)second, third);
  179. case SHMCTL:
  180. return sys_shmctl(first, (int)second,
  181. (struct shmid_ds __user *) ptr);
  182. default:
  183. return -ENOSYS;
  184. }
  185. return -EINVAL;
  186. }
  187. #ifdef CONFIG_64BIT
  188. asmlinkage long s390x_newuname(struct new_utsname __user *name)
  189. {
  190. int ret = sys_newuname(name);
  191. if (current->personality == PER_LINUX32 && !ret) {
  192. ret = copy_to_user(name->machine, "s390\0\0\0\0", 8);
  193. if (ret) ret = -EFAULT;
  194. }
  195. return ret;
  196. }
  197. asmlinkage long s390x_personality(unsigned long personality)
  198. {
  199. int ret;
  200. if (current->personality == PER_LINUX32 && personality == PER_LINUX)
  201. personality = PER_LINUX32;
  202. ret = sys_personality(personality);
  203. if (ret == PER_LINUX32)
  204. ret = PER_LINUX;
  205. return ret;
  206. }
  207. #endif /* CONFIG_64BIT */
  208. /*
  209. * Wrapper function for sys_fadvise64/fadvise64_64
  210. */
  211. #ifndef CONFIG_64BIT
  212. asmlinkage long
  213. s390_fadvise64(int fd, u32 offset_high, u32 offset_low, size_t len, int advice)
  214. {
  215. return sys_fadvise64(fd, (u64) offset_high << 32 | offset_low,
  216. len, advice);
  217. }
  218. #endif
  219. struct fadvise64_64_args {
  220. int fd;
  221. long long offset;
  222. long long len;
  223. int advice;
  224. };
  225. asmlinkage long
  226. s390_fadvise64_64(struct fadvise64_64_args __user *args)
  227. {
  228. struct fadvise64_64_args a;
  229. if ( copy_from_user(&a, args, sizeof(a)) )
  230. return -EFAULT;
  231. return sys_fadvise64_64(a.fd, a.offset, a.len, a.advice);
  232. }
  233. #ifndef CONFIG_64BIT
  234. /*
  235. * This is a wrapper to call sys_fallocate(). For 31 bit s390 the last
  236. * 64 bit argument "len" is split into the upper and lower 32 bits. The
  237. * system call wrapper in the user space loads the value to %r6/%r7.
  238. * The code in entry.S keeps the values in %r2 - %r6 where they are and
  239. * stores %r7 to 96(%r15). But the standard C linkage requires that
  240. * the whole 64 bit value for len is stored on the stack and doesn't
  241. * use %r6 at all. So s390_fallocate has to convert the arguments from
  242. * %r2: fd, %r3: mode, %r4/%r5: offset, %r6/96(%r15)-99(%r15): len
  243. * to
  244. * %r2: fd, %r3: mode, %r4/%r5: offset, 96(%r15)-103(%r15): len
  245. */
  246. asmlinkage long s390_fallocate(int fd, int mode, loff_t offset,
  247. u32 len_high, u32 len_low)
  248. {
  249. return sys_fallocate(fd, mode, offset, ((u64)len_high << 32) | len_low);
  250. }
  251. #endif